Skip to content

Commit

Permalink
Merge pull request #32 from memori-ai/birthdate
Browse files Browse the repository at this point in the history
fix: recover birthdate from localstorage or login
  • Loading branch information
nzambello authored Dec 5, 2024
2 parents 2aa5d23 + a462ec7 commit eff8017
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/components/MemoriWidget/MemoriWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ const MemoriWidget = ({
if (user && resultCode === 0) {
setUser(user);
setLocalConfig('loginToken', loginToken);

if (user.birthDate) {
setBirthDate(user.birthDate);
setLocalConfig('birthDate', user.birthDate);
}
} else {
removeLocalConfig('loginToken');
}
Expand Down Expand Up @@ -617,6 +622,8 @@ const MemoriWidget = ({
if (!additionalInfo?.loginToken && !authToken) {
setLoginToken(getLocalConfig<typeof loginToken>('loginToken', undefined));
userToken = getLocalConfig<typeof loginToken>('loginToken', undefined);

setBirthDate(getLocalConfig<string | undefined>('birthDate', undefined));
}
}, []);

Expand Down Expand Up @@ -1106,12 +1113,7 @@ const MemoriWidget = ({
dialogState: DialogState;
sessionID: string;
} | void> => {
// Check if age verification is needed
let storageBirthDate = getLocalConfig<string | undefined>(
'birthDate',
undefined
);
if (!(birthDate || storageBirthDate) && !!minAge) {
if (!birthDate && !!minAge) {
setShowAgeVerification(true);
return;
}
Expand Down Expand Up @@ -1231,12 +1233,7 @@ const MemoriWidget = ({
) => {
setLoading(true);
try {
// Check if age verification is needed
let storageBirthDate = getLocalConfig<string | undefined>(
'birthDate',
undefined
);
if (!(birthDate || storageBirthDate) && !!minAge) {
if (!birthDate && !!minAge) {
setShowAgeVerification(true);
return;
}
Expand Down Expand Up @@ -1279,7 +1276,7 @@ const MemoriWidget = ({
...(initialContextVars || {}),
},
initialQuestion,
birthDate: birthDate || storageBirthDate || undefined,
birthDate: birthDate || undefined,
additionalInfo: {
...(additionalInfo || {}),
loginToken:
Expand Down

0 comments on commit eff8017

Please sign in to comment.