mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-02 18:51:52 +02:00
🐛 Check for new session first (#1563)
This commit is contained in:
parent
ff4a1d16cb
commit
6979c091f2
3 changed files with 46 additions and 22 deletions
|
@ -15,19 +15,22 @@ export const withAuth = (
|
|||
middleware: (request: NextAuthRequest) => Promise<NextResponse>,
|
||||
) => {
|
||||
return async (request: NextAuthRequest) => {
|
||||
let legacySession: Session | null = null;
|
||||
let session: Session | null = null;
|
||||
|
||||
try {
|
||||
legacySession = await getLegacySession();
|
||||
session = await auth();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
let session = legacySession;
|
||||
let isLegacySession = false;
|
||||
|
||||
if (!session) {
|
||||
try {
|
||||
session = await auth();
|
||||
session = await getLegacySession();
|
||||
if (session) {
|
||||
isLegacySession = true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
@ -50,7 +53,7 @@ export const withAuth = (
|
|||
|
||||
const middlewareRes = await middleware(request);
|
||||
|
||||
if (legacySession) {
|
||||
if (isLegacySession) {
|
||||
try {
|
||||
await migrateLegacyJWT(middlewareRes);
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue