Update usage
This commit is contained in:
@@ -22,7 +22,10 @@ import {
|
|||||||
import {useAgent, useSession} from '#/state/session'
|
import {useAgent, useSession} from '#/state/session'
|
||||||
import * as debug from '#/ageAssurance/debug'
|
import * as debug from '#/ageAssurance/debug'
|
||||||
import {logger} from '#/ageAssurance/logger'
|
import {logger} from '#/ageAssurance/logger'
|
||||||
import {isLegacyBirthdateBug} from '#/ageAssurance/util'
|
import {
|
||||||
|
getBirthdateStringFromAge,
|
||||||
|
isLegacyBirthdateBug,
|
||||||
|
} from '#/ageAssurance/util'
|
||||||
import {IS_DEV} from '#/env'
|
import {IS_DEV} from '#/env'
|
||||||
import {device} from '#/storage'
|
import {device} from '#/storage'
|
||||||
|
|
||||||
@@ -327,15 +330,16 @@ export async function getOtherRequiredData({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If we can't read a birthdate, it may be due to the user accessing the
|
* If we can't read a birthdate, it may be due to the user accessing the
|
||||||
* account via an app password. In that case, fall-back to
|
* account via an app password. In that case, fall-back to declared age
|
||||||
* `isDeclaredOverAgeMinimum` and other flags.
|
* flags.
|
||||||
*/
|
*/
|
||||||
if (!data.birthdate) {
|
if (!data.birthdate) {
|
||||||
if (prefs.isDeclaredOverAgeMinimum) {
|
if (prefs.declaredAge?.isOverAge18) {
|
||||||
const approx = new Date()
|
data.birthdate = getBirthdateStringFromAge(18)
|
||||||
approx.setFullYear(approx.getFullYear() - 13)
|
} else if (prefs.declaredAge?.isOverAge16) {
|
||||||
approx.setDate(approx.getDate() - 1) // ensure we're past
|
data.birthdate = getBirthdateStringFromAge(16)
|
||||||
data.birthdate = approx.toISOString()
|
} else if (prefs.declaredAge?.isOverAge13) {
|
||||||
|
data.birthdate = getBirthdateStringFromAge(13)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,3 +86,12 @@ export function isUserUnderMinimumAge(birthDate: string) {
|
|||||||
export function isUserUnderAdultAge(birthDate: string) {
|
export function isUserUnderAdultAge(birthDate: string) {
|
||||||
return getAge(new Date(birthDate)) < 18
|
return getAge(new Date(birthDate)) < 18
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getBirthdateStringFromAge(age: number) {
|
||||||
|
const today = new Date()
|
||||||
|
return new Date(
|
||||||
|
today.getFullYear() - age,
|
||||||
|
today.getMonth(),
|
||||||
|
today.getDate() - 1, // set to day before to ensure age is reached
|
||||||
|
).toISOString()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user