next-auth中间件未正确评估JS

guicsvcw  于 2023-05-06  发布在  其他
关注(0)|答案(2)|浏览(85)

我在next-auth middleware.js文件中遇到了一个奇怪的行为:
下面的代码可以工作:

export {default} from 'next-auth/middleware'

export const config = {
    matcher: ['/dashboard'],
    pages: {
        signIn: 'http://localhost:8000/accounts/login',
        error: '/api/auth/error',
    },
}

...而下面的则不会(将每个路由重定向到 /API/auth/signin?callbackUrl=%2F):

export {default} from 'next-auth/middleware'

export const config = {
    matcher: ['/dashboard'],
    pages: {
        signIn: 'http://localhost:8000' + '/accounts/login', // <== NOTICE THE STRING CONCATENATION HERE
        error: '/api/auth/error',
    },
}

我在next@13.4next-auth^4.20.1上。
有谁知道这是怎么回事吗?

h6my8fg2

h6my8fg21#

我怀疑Next webpack配置是将pages字段解析为您的实际页面,当它是一个常量字符串时,但当连接时,它无法在编译时解析。
根据Next文档,pages字段不应包含主机部分:
这应该与[... nextauth]. ts中的页面配置匹配。
further here
使用此配置时,请确保这些页确实存在。例如错误:“/auth/error”指的是位于pages/auth/error.js的页面文件

pages: {
  signIn: '/api/auth/signin',
  error: '/api/auth/error',
}
6ljaweal

6ljaweal2#

我认为这与编码问题有关。试试这个

  • new URL(url, [base])
new URL('/accounts/login','http://localhost:8000' )

相关问题