Update usage

This commit is contained in:
Eric Bailey
2025-12-09 15:33:03 -06:00
parent 6db3e902a3
commit be4fbbff46
2 changed files with 21 additions and 8 deletions
+12 -8
View File
@@ -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)
} }
} }
+9
View File
@@ -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()
}