🐛 Fix login error (#932)

This commit is contained in:
Luke Vella 2023-11-08 16:14:09 +00:00 committed by GitHub
parent 3f6a5603b3
commit e3aacbe668
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 141 additions and 176 deletions

View file

@ -1,7 +1,6 @@
"use client";
import Cookies from "js-cookie";
import { Session } from "next-auth";
import { signIn, useSession } from "next-auth/react";
import { useSession } from "next-auth/react";
import React from "react";
import { z } from "zod";
@ -59,27 +58,7 @@ export const IfGuest = (props: { children?: React.ReactNode }) => {
};
export const UserProvider = (props: { children?: React.ReactNode }) => {
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,
// otherwise when the user signs out.
if (legacyToken) {
Cookies.remove("legacy-token");
signIn("legacy-token", {
token: legacyToken,
redirect: false,
});
} else {
// End: Legacy token migration
signIn("guest", {
redirect: false,
});
}
},
});
const session = useSession();
const user = session.data?.user;