Authentication Next.js redirects-如果用户没有令牌,则重定向
根据next.js文档,我想不出正确的方法 目前,如果用户有令牌,我可以从Authentication Next.js redirects-如果用户没有令牌,则重定向,authentication,redirect,cookies,next.js,Authentication,Redirect,Cookies,Next.js,根据next.js文档,我想不出正确的方法 目前,如果用户有令牌,我可以从/user/login重定向用户,但如果他们没有令牌,我无法想出如何从/user/login>重定向用户: module.exports = { future: { webpack5: true, }, async redirects() { return [ { source: '/user/:path*', has: [ {
/user/login
重定向用户,但如果他们没有令牌,我无法想出如何从/user/login>重定向用户:
module.exports = {
future: {
webpack5: true,
},
async redirects() {
return [
{
source: '/user/:path*',
has: [
{
type: 'cookie',
key: 'token',
// value: undefined,
}
],
permanent: true,
destination: '/dashboard',
}
];
},
}
您可以像上面一样设置要检查的自定义无令牌头或cookie,或者设置非http唯一cookie并检查客户端。