From 4c180012b87473f6224f937fe0176af9cf86c4d3 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sun, 16 Nov 2025 08:17:20 +0000 Subject: [PATCH] completionId: cgen-9c165472fa87466c8c034000852c961f cgen-9c165472fa87466c8c034000852c961f --- api/discord/oauth/start.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/api/discord/oauth/start.ts b/api/discord/oauth/start.ts index f6e27cd0..12636e6c 100644 --- a/api/discord/oauth/start.ts +++ b/api/discord/oauth/start.ts @@ -12,12 +12,9 @@ export default function handler(req: any, res: any) { return res.status(500).json({ error: "Discord client ID not configured" }); } - // Get the current API base from the request origin - const protocol = - req.headers["x-forwarded-proto"] || req.headers.protocol || "https"; - const host = req.headers["x-forwarded-host"] || req.headers.host; - const apiBase = `${protocol}://${host}`; - + // Use the main API base domain to ensure the redirect_uri matches the registered one + // This is critical because Discord OAuth requires exact match of redirect_uri + const apiBase = process.env.VITE_API_BASE || "https://aethex.dev"; const redirectUri = `${apiBase}/api/discord/oauth/callback`; // Get the state from query params (can be a JSON string with action and redirectTo)