mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-01 19:26:30 +02:00
Update migrate
This commit is contained in:
parent
694249c024
commit
07503e4552
1 changed files with 24 additions and 17 deletions
|
@ -54,14 +54,19 @@ export async function migrateGuestFromNextAuthCookie(
|
||||||
res: NextResponse,
|
res: NextResponse,
|
||||||
) {
|
) {
|
||||||
const { name } = getNextAuthCookieSettings();
|
const { name } = getNextAuthCookieSettings();
|
||||||
if (req.cookies.has(name)) {
|
|
||||||
// get user session token
|
|
||||||
const token = req.cookies.get(name)?.value;
|
const token = req.cookies.get(name)?.value;
|
||||||
if (token) {
|
|
||||||
|
if (!token) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const jwt = await decode({
|
const jwt = await decode({
|
||||||
token,
|
token,
|
||||||
secret: process.env.SECRET_PASSWORD,
|
secret: process.env.SECRET_PASSWORD,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (jwt?.sub && jwt?.locale) {
|
if (jwt?.sub && jwt?.locale) {
|
||||||
const user = await createGuestUser({
|
const user = await createGuestUser({
|
||||||
id: jwt.sub,
|
id: jwt.sub,
|
||||||
|
@ -72,7 +77,9 @@ export async function migrateGuestFromNextAuthCookie(
|
||||||
});
|
});
|
||||||
res.cookies.set(GUEST_USER_COOKIE, JSON.stringify(user));
|
res.cookies.set(GUEST_USER_COOKIE, JSON.stringify(user));
|
||||||
}
|
}
|
||||||
}
|
} catch (error) {
|
||||||
|
console.error("Failed to decode JWT:", error);
|
||||||
|
res.cookies.delete(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue