mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-05 05:06:04 +02:00
♻️ Update handling of unauthenticated user
This commit is contained in:
parent
3da803a41a
commit
481fcc0471
1 changed files with 15 additions and 13 deletions
|
@ -58,14 +58,9 @@ export const IfGuest = (props: { children?: React.ReactNode }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const UserProvider = (props: { children?: React.ReactNode }) => {
|
export const UserProvider = (props: { children?: React.ReactNode }) => {
|
||||||
const session = useSession();
|
const session = useSession({
|
||||||
|
required: true,
|
||||||
const user = session.data?.user;
|
onUnauthenticated() {
|
||||||
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (session.status === "unauthenticated") {
|
|
||||||
// Begin: Legacy token migration
|
// Begin: Legacy token migration
|
||||||
const legacyToken = Cookies.get("legacy-token");
|
const legacyToken = Cookies.get("legacy-token");
|
||||||
// It's important to remove the token from the cookies,
|
// 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");
|
Cookies.remove("legacy-token");
|
||||||
signIn("legacy-token", {
|
signIn("legacy-token", {
|
||||||
token: legacyToken,
|
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) {
|
if (!user) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue