你好,我试图在fetchUser方法后获取用户名,但未定义
我正在这样尝试
async loginUser() {
this.$auth.setUserToken(`${this.token}`);
this.$auth.setStrategy('local');
await this.$auth
.fetchUser()
.then(() => {
console.log(this.$auth.user); //<- this getting false i want user details
})
.catch(e => {
// console.log(e)
this.$auth.logout();
return this.$router.push(
`/${
this.$route.query.origin ? this.$route.query.origin : 'register'
}?error=1`,
);
});
},
我使用此逻辑对其进行了修复
async loginUser() {
this.$auth.setUserToken(`${this.token}`);
this.$auth.setStrategy('local');
await this.$auth
.fetchUser()
.then(() => {
//Added This for get user details then redirect to username page
this.$axios.get('/me').then(response => {
return this.$router.push(`/${response.data.data.username}`);
});
})
.catch(e => {
// console.log(e)
this.$auth.logout();
return this.$router.push(
`/${
this.$route.query.origin ? this.$route.query.origin : 'register'
}?error=1`,
);
});
},