♻️ Update handling of unauthenticated user

This commit is contained in:
Luke Vella 2023-11-04 16:24:42 +00:00
parent 3da803a41a
commit 481fcc0471

View file

@ -58,14 +58,9 @@ export const IfGuest = (props: { children?: React.ReactNode }) => {
};
export const UserProvider = (props: { children?: React.ReactNode }) => {
const session = useSession();
const user = session.data?.user;
const { t } = useTranslation();
React.useEffect(() => {
if (session.status === "unauthenticated") {
const session = useSession({
required: true,
onUnauthenticated() {
// Begin: Legacy token migration
const legacyToken = Cookies.get("legacy-token");
// It's important to remove the token from the cookies,
@ -74,13 +69,20 @@ export const UserProvider = (props: { children?: React.ReactNode }) => {
Cookies.remove("legacy-token");
signIn("legacy-token", {
token: legacyToken,
redirect: false,
});
} else {
// End: Legacy token migration
signIn("guest", {
redirect: false,
});
return;
}
// End: Legacy token migration
signIn("guest");
}
}, [session.status]);
},
});
const user = session.data?.user;
const { t } = useTranslation();
if (!user) {
return null;