fix: use FRONTEND_URL for redirects behind proxy
Build and Deploy / test-backend (push) Successful in 55s
Build and Deploy / lint-frontend (push) Successful in 12s
Build and Deploy / build-backend (push) Successful in 3s
Build and Deploy / build-frontend (push) Successful in 29s
Build and Deploy / deploy (push) Successful in 5s

This commit is contained in:
Ivan Rezchikov
2026-09-18 01:50:22 +03:00
parent 7d46042102
commit c84b18faa8
3 changed files with 9 additions and 8 deletions
+4 -2
View File
@@ -11,9 +11,11 @@ export async function GET(req: Request) {
const storedState = cookieStore.get("oauth_state")?.value;
const verifier = cookieStore.get("oauth_verifier")?.value;
const origin = new URL(process.env.FRONTEND_URL ?? "http://localhost:3000").origin;
const fail = (reason: string) => {
const response = NextResponse.redirect(
new URL(`/oauth/error?reason=${reason}`, url.origin)
new URL(`/oauth/error?reason=${reason}`, origin)
);
response.cookies.delete("oauth_verifier");
response.cookies.delete("oauth_state");
@@ -47,7 +49,7 @@ export async function GET(req: Request) {
const { session_token } = await sessionResponse.json();
const response = NextResponse.redirect(new URL("/collections", url.origin));
const response = NextResponse.redirect(new URL("/collections", origin));
response.cookies.set("session", session_token, {
httpOnly: true,
+4 -6
View File
@@ -1,16 +1,14 @@
import { NextResponse } from "next/server";
import { cookies, headers as fetchHeaders } from "next/headers";
import { cookies } from "next/headers";
import { generateCodeVerifier, generateCodeChallenge, generateState } from "@/lib/pkce";
const FLOW_TTL = 60 * 10;
const origin = () => new URL(process.env.FRONTEND_URL ?? "http://localhost:3000").origin;
export async function GET() {
if ((await cookies()).get("session")) {
const headers = await fetchHeaders();
const protocol = headers.get("x-forwarded-proto") ?? "http";
const host = headers.get("host");
const origin = host ? `${protocol}://${host}` : "http://localhost:3000";
return NextResponse.redirect(new URL("/", origin));
return NextResponse.redirect(new URL("/", origin()));
}
const verifier = generateCodeVerifier();