diff --git a/api/discord/oauth/callback.ts b/api/discord/oauth/callback.ts index 02bd23e8..3161cc2f 100644 --- a/api/discord/oauth/callback.ts +++ b/api/discord/oauth/callback.ts @@ -116,10 +116,9 @@ export default async function handler(req: any, res: any) { } try { - // Get the current API base from the request origin - const protocol = req.headers["x-forwarded-proto"] || "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`; // Exchange code for access token