mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-02 18:51:52 +02:00
🐛 Clean up expired jwt (#1628)
This commit is contained in:
parent
701875a158
commit
897cdb4cfd
4 changed files with 27 additions and 15 deletions
|
@ -5,6 +5,7 @@ import NextAuth from "next-auth";
|
|||
import { nextAuthConfig } from "@/next-auth.config";
|
||||
|
||||
import {
|
||||
deleteLegacyCookie,
|
||||
getLegacySession,
|
||||
migrateLegacyJWT,
|
||||
} from "../legacy/next-auth-cookie-migration";
|
||||
|
@ -24,6 +25,7 @@ export const withAuth = (
|
|||
}
|
||||
|
||||
let isLegacySession = false;
|
||||
let isExpiredLegacySession = false;
|
||||
|
||||
if (!session) {
|
||||
try {
|
||||
|
@ -32,7 +34,7 @@ export const withAuth = (
|
|||
isLegacySession = true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
isExpiredLegacySession = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,6 +56,7 @@ export const withAuth = (
|
|||
const middlewareRes = await middleware(request);
|
||||
|
||||
if (isLegacySession) {
|
||||
console.warn("Found legacy session, migrating…");
|
||||
try {
|
||||
await migrateLegacyJWT(middlewareRes);
|
||||
} catch (e) {
|
||||
|
@ -61,6 +64,11 @@ export const withAuth = (
|
|||
}
|
||||
}
|
||||
|
||||
if (isExpiredLegacySession) {
|
||||
console.warn("Found expired legacy session, deleting…");
|
||||
deleteLegacyCookie(middlewareRes);
|
||||
}
|
||||
|
||||
return middlewareRes;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue