Update fallback origin in getSiteOrigin to production domain to prevent localhost in OAuth redirects

This commit is contained in:
root
2026-07-03 03:16:32 +00:00
parent 8120a09a0c
commit ca3f756cf3
3 changed files with 13 additions and 8 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ function getOrigin(req?: Request): string {
return url.origin;
} catch {}
}
return process.env.NEXT_PUBLIC_SITE_URL ?? 'http://localhost:3000';
return process.env.NEXT_PUBLIC_SITE_URL ?? 'https://shahikitchen.se';
}
export async function GET(request: Request) {
+1 -1
View File
@@ -52,5 +52,5 @@ function getOrigin(req?: Request): string {
return url.origin;
} catch {}
}
return process.env.NEXT_PUBLIC_SITE_URL ?? 'http://localhost:3000';
return process.env.NEXT_PUBLIC_SITE_URL ?? 'https://shahikitchen.se';
}
+11 -6
View File
@@ -11,15 +11,20 @@ export function isGoogleOAuthConfigured(): boolean {
export function getSiteOrigin(req?: Request): string {
if (req) {
try {
const url = new URL(req.url);
// In production behind nginx, prefer https even if internal request is http
if (process.env.NODE_ENV === 'production' && url.protocol === 'http:') {
url.protocol = 'https:';
const h = req.headers;
const host = h.get('x-forwarded-host') || h.get('host');
let proto = h.get('x-forwarded-proto') || 'https';
if (proto.includes(',')) proto = proto.split(',')[0].trim();
if (host) {
// ensure https in prod
if (process.env.NODE_ENV === 'production' && proto === 'http') {
proto = 'https';
}
return `${proto}://${host}`;
}
return url.origin;
} catch {}
}
return process.env.NEXT_PUBLIC_SITE_URL ?? 'http://localhost:3000';
return process.env.NEXT_PUBLIC_SITE_URL ?? 'https://shahikitchen.se';
}
export function getGoogleRedirectUri(req?: Request): string {