completionId: cgen-67d0dd19c88f4f189507f0fb95cd9ec3
cgen-67d0dd19c88f4f189507f0fb95cd9ec3
This commit is contained in:
parent
9e0f53751d
commit
e1ae88a7be
1 changed files with 13 additions and 11 deletions
|
|
@ -282,22 +282,24 @@ export default async function handler(req: any, res: any) {
|
||||||
await notifyAccountLinked(userId, "Discord");
|
await notifyAccountLinked(userId, "Discord");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate session token
|
// Generate a magic link to establish session
|
||||||
const { data: sessionData, error: sessionError } =
|
const { data: linkData, error: linkError } =
|
||||||
await supabase.auth.admin.createSession({
|
await supabase.auth.admin.generateLink({
|
||||||
user_id: userId,
|
type: "magiclink",
|
||||||
|
email: discordUser.email,
|
||||||
|
options: {
|
||||||
|
redirectTo: redirectTo,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sessionError || !sessionData.session) {
|
if (linkError || !linkData?.properties?.magic_link) {
|
||||||
console.error("[Discord OAuth] Session creation failed:", sessionError);
|
console.error("[Discord OAuth] Magic link generation failed:", linkError);
|
||||||
return res.redirect("/login?error=session_create");
|
return res.redirect("/login?error=session_create");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set session cookies
|
// Redirect to magic link to establish session
|
||||||
const accessTokenCookie = `sb-access-token=${sessionData.session.access_token}; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=3600`;
|
// The magic link contains the session token and will set cookies automatically
|
||||||
const refreshTokenCookie = `sb-refresh-token=${sessionData.session.refresh_token}; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=604800`;
|
res.redirect(linkData.properties.magic_link);
|
||||||
|
|
||||||
res.setHeader("Set-Cookie", [accessTokenCookie, refreshTokenCookie]);
|
|
||||||
|
|
||||||
// Redirect to dashboard (we only log in existing users here)
|
// Redirect to dashboard (we only log in existing users here)
|
||||||
const nextPath = "/dashboard";
|
const nextPath = "/dashboard";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue