Update fallback origin in getSiteOrigin to production domain to prevent localhost in OAuth redirects
This commit is contained in:
@@ -39,7 +39,7 @@ function getOrigin(req?: Request): string {
|
|||||||
return url.origin;
|
return url.origin;
|
||||||
} catch {}
|
} 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) {
|
export async function GET(request: Request) {
|
||||||
|
|||||||
@@ -52,5 +52,5 @@ function getOrigin(req?: Request): string {
|
|||||||
return url.origin;
|
return url.origin;
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
return process.env.NEXT_PUBLIC_SITE_URL ?? 'http://localhost:3000';
|
return process.env.NEXT_PUBLIC_SITE_URL ?? 'https://shahikitchen.se';
|
||||||
}
|
}
|
||||||
@@ -11,15 +11,20 @@ export function isGoogleOAuthConfigured(): boolean {
|
|||||||
export function getSiteOrigin(req?: Request): string {
|
export function getSiteOrigin(req?: Request): string {
|
||||||
if (req) {
|
if (req) {
|
||||||
try {
|
try {
|
||||||
const url = new URL(req.url);
|
const h = req.headers;
|
||||||
// In production behind nginx, prefer https even if internal request is http
|
const host = h.get('x-forwarded-host') || h.get('host');
|
||||||
if (process.env.NODE_ENV === 'production' && url.protocol === 'http:') {
|
let proto = h.get('x-forwarded-proto') || 'https';
|
||||||
url.protocol = '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 {}
|
} 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 {
|
export function getGoogleRedirectUri(req?: Request): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user