fix(github-oauth): use NEXTAUTH_URL for redirect_uri instead of req.url.origin
Behind Coolify's proxy, req.url resolves to 0.0.0.0:3000 which GitHub rejects as an unregistered redirect URI. Prefer NEXTAUTH_URL env var. Made-with: Cursor
This commit is contained in:
@@ -33,7 +33,11 @@ export async function GET(req: Request) {
|
||||
}
|
||||
|
||||
const url = new URL(req.url);
|
||||
const callbackUrl = `${url.origin}/api/integrations/github/callback`;
|
||||
// Use NEXTAUTH_URL when available — behind a proxy req.url.origin
|
||||
// resolves to the internal bind address (0.0.0.0) rather than the
|
||||
// public hostname, which GitHub then rejects as an unregistered URI.
|
||||
const appOrigin = (process.env.NEXTAUTH_URL ?? url.origin).replace(/\/$/, "");
|
||||
const callbackUrl = `${appOrigin}/api/integrations/github/callback`;
|
||||
const returnTo = url.searchParams.get("returnTo") ?? "/";
|
||||
|
||||
const state = randomBytes(16).toString("hex");
|
||||
|
||||
Reference in New Issue
Block a user