我正在尝试使用Nuxt Auth模块和社交名流进行社交登录。我在Laravel 8中有一个API,在NuxtJS中有一个客户端。
我想知道是否有人能告诉我:
手动登录用户
因此,目前我的社交登录流程如下:
login with google对我的后端进行API调用,从社交网站获得重定向URL到google。return $this->okResponse(['token' => $nativeUser->createToken('social-login')->accessToken]);this.$auth.setUserToken(response.data.token),这显然不等于登录用户。看起来是这样的:mounted() {
this.$axios.get(`login/social/google/callback`, {params: {code: this.$route.query.code}}).then(response => {
console.log(response)
// this.$auth.strategy.token.set(response.data.token)
this.$auth.setUserToken(response.data.token)
if (this.$auth.loggedIn) {
console.log('I am logged in!')
} else {
console.log('I am NOT logged in!', this.$auth)
}
})
}我没有登录。我必须手动设置loggedIn、'User‘和token吗?还是这就是疯狂?我在这里看到的唯一解决方案是我自己的自定义策略,但这似乎完全过火了。
发布于 2021-09-25 18:56:54
不知道这是不是最好的方法,但我最后做了这样的事情。
mounted() {
this.$axios.get(`login/social/google/callback`, {params: {code: this.$route.query.code}}).then(response => {
this.$auth.setUserToken(response.data.token)
this.$auth.setUser(response.data.user)
if (this.$auth.loggedIn) {
console.log('I am logged in!')
} else {
console.log('I am NOT logged in!', this.$auth)
}
})
}这件事似乎还好。
https://stackoverflow.com/questions/69328275
复制相似问题