Handle existing email in Discord OAuth callback - redirect to link flow instead of failing
cgen-79dca6287ad14c33b0b54d7103dad109
This commit is contained in:
parent
07a78a05c0
commit
1c97614eea
1 changed files with 14 additions and 0 deletions
|
|
@ -163,6 +163,20 @@ export default async function handler(req: any, res: any) {
|
|||
});
|
||||
|
||||
if (authError || !authData.user) {
|
||||
// Check if error is because email already exists
|
||||
if (
|
||||
authError?.message &&
|
||||
authError.message.toLowerCase().includes("already")
|
||||
) {
|
||||
console.log(
|
||||
"[Discord OAuth] Email already registered, redirecting to link flow",
|
||||
);
|
||||
// Redirect to login page where user can link Discord to existing account
|
||||
return res.redirect(
|
||||
`/login?error=account_exists&message=${encodeURIComponent("Please sign in first, then link your Discord account from settings")}`,
|
||||
);
|
||||
}
|
||||
|
||||
console.error("[Discord OAuth] Auth user creation failed:", {
|
||||
email: discordUser.email,
|
||||
username: discordUser.username,
|
||||
|
|
|
|||
Loading…
Reference in a new issue