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 * as debug from '#/ageAssurance/debug'
import {logger} from '#/ageAssurance/logger'
import {isLegacyBirthdateBug} from '#/ageAssurance/util'
import {
getBirthdateStringFromAge,
isLegacyBirthdateBug,
} from '#/ageAssurance/util'
import {IS_DEV} from '#/env'
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
* account via an app password. In that case, fall-back to
* `isDeclaredOverAgeMinimum` and other flags.
* account via an app password. In that case, fall-back to declared age
* flags.
*/
if (!data.birthdate) {
if (prefs.isDeclaredOverAgeMinimum) {
const approx = new Date()
approx.setFullYear(approx.getFullYear() - 13)
approx.setDate(approx.getDate() - 1) // ensure we're past
data.birthdate = approx.toISOString()
if (prefs.declaredAge?.isOverAge18) {
data.birthdate = getBirthdateStringFromAge(18)
} else if (prefs.declaredAge?.isOverAge16) {
data.birthdate = getBirthdateStringFromAge(16)
} 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) {
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()
}