0

I have an app that authenticates against Azure AD using next-auth 4. It works fine and I can authenticate.

When I try to configure a custom base path http://localhost:3000/myapp for the app and call signIn() I get a 404 error telling me that http://localhost:3000/api/auth/error is not found.

I have configured all the paths like described below.

What confuses me:

  • If I use the standard path I notice that [...nextauth.js] gets executed
  • If I use a custom path, [...nextauth.js] is not even executed

A similar scenario in next.auth 3 worked just fine.

Comparing to next-auth 3 it looks like next-auth 4 does not honor NEXTAUTH_URL.

What can I do?

.env.local

AZURE_CLIENT_ID= ....
AZURE_CLIENT_SECRET=...
AZURE_TENANT_ID=...

JWT_SECRET=...

NEXTAUTH_URL=http://localhost:3000/myapp/api/auth
NEXTAUTH_URL_INTERNAL=http://localhost:3000/mypp/api/auth
NEXT_AUTH_DEBUG=true

APP_BASE_PATH=/myapp

next.config.js:

const basePath = process.env.APP_BASE_PATH;

module.exports = {
  reactStrictMode: true,
  basePath: `${basePath}`,
};

[...nextauth.js]`


export default NextAuth({
  providers: [
    AzureADProvider({
      clientId: process.env.AZURE_CLIENT_ID,
      clientSecret: process.env.AZURE_CLIENT_SECRET,
      scope: "offline_access User.Read",
      tenantId: process.env.AZURE_TENANT_ID,
    }),
  ],
....
  debug: process.env.NEXT_AUTH_DEBUG,
  secret: process.env.JWT_SECRET,
});
Community
  • 1
  • 1
Robert Hufsky
  • 131
  • 3
  • 16

1 Answers1

0

Did you've tried that solution ?

Try to edit your _app.tsx and define your base path using the props basePath on your , as in that example.

R. Boutte
  • 524
  • 1
  • 4
  • 15