Skip to content

Commit

Permalink
リバースプロキシ下で動作するように修正
Browse files Browse the repository at this point in the history
nextauthjs/next-auth#10928 (comment)
とかに対処法がある
  • Loading branch information
Daiius committed Sep 24, 2024
1 parent b071568 commit cc2a8ac
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
import { handlers } from "@/auth" // Referring to the auth.ts we just created
export const { GET, POST } = handlers
export const runtime = "edge" // optional
import { NextRequest } from 'next/server';
//export const { GET, POST } = handlers
//export const runtime = "edge" // optional

const basePath = '/sekirei-todo';

const toForwardedRequest = (req: NextRequest): NextRequest => {
const forwardedHost = req.headers.get('x-forwarded-host');
const forwardedProto = req.headers.get('x-forwarded-proto');
if (forwardedHost && forwardedProto) {
const forwardedUrl =
`${forwardedProto}://${forwardedHost}${basePath}${req.nextUrl.pathname}?${req.nextUrl.searchParams.toString()}`;
const newReq = new NextRequest(forwardedUrl, {
headers: req.headers,
method: req.method,
body: req.body,
});
return newReq;
} else {
return req;
}
}

export const GET: (req: NextRequest) => Promise<Response> =
(req) => handlers.GET(toForwardedRequest(req));

export const POST: (req: NextRequest) => Promise<Response> =
(req) => handlers.POST(toForwardedRequest(req));

0 comments on commit cc2a8ac

Please sign in to comment.