Make Google OAuth redirect_uri dynamic based on request origin to support both shahikitchen.se and www.shahikitchen.se
This commit is contained in:
@@ -16,7 +16,7 @@ const OAUTH_STATE_COOKIE = 'shahi_google_oauth_state';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
if (!isGoogleOAuthConfigured()) {
|
||||
return NextResponse.redirect(new URL('/login?tab=customer&error=google_not_configured', getOrigin()));
|
||||
return NextResponse.redirect(new URL('/login?tab=customer&error=google_not_configured', getOrigin(request)));
|
||||
}
|
||||
|
||||
const url = new URL(request.url);
|
||||
@@ -39,9 +39,18 @@ export async function GET(request: Request) {
|
||||
maxAge: 600,
|
||||
});
|
||||
|
||||
return NextResponse.redirect(buildGoogleAuthUrl(state));
|
||||
return NextResponse.redirect(buildGoogleAuthUrl(state, request));
|
||||
}
|
||||
|
||||
function getOrigin(): string {
|
||||
function getOrigin(req?: Request): string {
|
||||
if (req) {
|
||||
try {
|
||||
const url = new URL(req.url);
|
||||
if (process.env.NODE_ENV === 'production' && url.protocol === 'http:') {
|
||||
url.protocol = 'https:';
|
||||
}
|
||||
return url.origin;
|
||||
} catch {}
|
||||
}
|
||||
return process.env.NEXT_PUBLIC_SITE_URL ?? 'http://localhost:3000';
|
||||
}
|
||||
Reference in New Issue
Block a user