[英]Guest middleware on Nuxt Auth not working
I have a login page that I would like for logged in users not be able to see.我有一个登录页面,我希望登录的用户无法看到。 My component is as follow:
我的组件如下:
<template>...</template>
<script lang="ts">
...
@Component({
layout: 'fullWidth',
auth: 'guest',
components: {
Base,
BaseAuth,
}
})
export default class Login extends Vue { ... }
</script>
After login if I go to the /login
route it allows me to view the page.登录后,如果我 go 到
/login
路由,它允许我查看页面。 My nuxt configuration is as follow:我的nuxt配置如下:
auth: {
redirect: {
login: '/login',
logout: '/',
// callback: '/login',
home: '/'
},
strategies: {
local: {
endpoints: {
login: { url: '/auth/login', method: 'post', propertyName: 'token' },
logout: { url: '/auth/logout', method: 'post' },
user: { url: '/auth/user', method: 'get', propertyName: 'user' }
},
}
}
}
Is there any other configuration that I should do?还有其他我应该做的配置吗?
i know it's not a real solution for the module, but what i end up doing was adding a hook on the login page:我知道这不是模块的真正解决方案,但我最终做的是在登录页面上添加一个钩子:
mounted() {
if (this.$auth.loggedIn) {
return this.$router.push('/dashboard')
}
},
use this, first register the middleware then use auth.使用这个,首先注册中间件然后使用 auth。
middleware: 'auth', auth: 'guest',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.