Skip to content

Commit

Permalink
FEAT: multidomain support
Browse files Browse the repository at this point in the history
  • Loading branch information
IncognitoTGT committed Jun 12, 2024
1 parent 1ebc4dd commit c647a6c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
import { handlers } from "@/lib/auth";
export const { GET, POST } = handlers;
import { NextRequest } from "next/server";

const reqWithTrustedOrigin = (req: NextRequest): NextRequest => {
const proto = req.headers.get("x-forwarded-proto");
const host = req.headers.get("x-forwarded-host");
if (!proto || !host) {
console.warn("Missing x-forwarded-proto or x-forwarded-host headers.");
return req;
}
const envOrigin = `${proto}://${host}`;
const { href, origin } = req.nextUrl;
return new NextRequest(href.replace(origin, envOrigin), req);
};

export const GET = (req: NextRequest) => {
return handlers.GET(reqWithTrustedOrigin(req));
};

export const POST = (req: NextRequest) => {
return handlers.POST(reqWithTrustedOrigin(req));
};

0 comments on commit c647a6c

Please sign in to comment.