79183468

Date: 2024-11-13 04:59:33
Score: 1
Natty:
Report link

I answered a similar question here:

In summary, this is currently still an issue in next-auth v5 beta. You can read up on them at:

The two workarounds from the first link are:

  1. @k3k8 solution (source):

    git clone -b fix-base-path https://github.com/k3k8/next-auth.git
    cd next-auth
    corepack enable pnpm
    pnpm install
    pnpm build
    cd packages/next-auth/
    pnpm pack
    

    This will generate a package file named something like next-auth-5.0.0-beta.20.tgz.

    Move this file to your project directory and install it by updating your package.json:

    {
      "dependencies": {
        "next-auth": "./next-auth-5.0.0-beta.20.tgz"
      }
    }
    

    Then run pnpm install

  2. @ThangHuuVu's solution (source):

    // app/api/auth/[...nextauth]/route.ts
    import { handlers } from "auth";
    import { NextRequest } from "next/server";
    
    const reqWithBasePath = (req: NextRequest, basePath = "/authjs") => {
      const baseUrl = new URL(
        (req.headers.get("x-forwarded-proto") ?? "https") +
          "://" +
          (req.headers.get("x-forwarded-host") ?? req.nextUrl.host)
      );
      const urlWithBasePath = new URL(
        `${basePath}${req.nextUrl.pathname}${req.nextUrl.search}`,
        baseUrl
      );
      return new NextRequest(urlWithBasePath.toString(), req);
    };
    
    export const GET = (req: NextRequest) => {
      const nextReq = reqWithBasePath(req);
      return handlers.GET(nextReq);
    };
    
    export const POST = (req: NextRequest) => {
      const nextReq = reqWithBasePath(req);
      return handlers.POST(nextReq);
    };
    

    https://github.com/ThangHuuVu/next-auth-behind-proxy/blob/cde4368b46fbda57157d62eaf1b93b258f5fadde/app/api/auth/%5B...nextauth%5D/route.ts

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: nktnet