【问题标题】:next-auth 4 custom base pathnext-auth 4 自定义基本路径
【发布时间】:2022-03-05 23:46:59
【问题描述】:

我有一个使用 next-auth 4 对 Azure AD 进行身份验证的应用。 它工作正常,我可以进行身份​​验证。

当我尝试为应用程序配置自定义基本路径 http://localhost:3000/myapp 并调用 signIn() 时,我收到一个 404 错误,告诉我找不到 http://localhost:3000/api/auth/error

我已经配置了如下所述的所有路径。

什么让我困惑:

  • 如果我使用标准路径,我注意到 [...nextauth.js] 会被执行
  • 如果我使用自定义路径,甚至不会执行 [...nextauth.js]

next.auth 3 中的类似场景运行良好。

与 next-auth 3 相比,看起来 next-auth 4 不支持 NEXTAUTH_URL。

我能做什么?

.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

下一个.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,
});

【问题讨论】:

    标签: next.js next-auth


    【解决方案1】:

    你试过that solution吗?

    尝试编辑您的 _app.tsx 并使用您的 上的 props basePath 定义您的基本路径,如that example

    【讨论】:

      猜你喜欢
      • 2021-08-17
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2023-01-18
      • 1970-01-01
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      相关资源
      最近更新 更多