当客户端从商店模块到达用户时,我使用django/django-graphql-auth
并且现在正在尝试了解身份验证策略。我关注了很多文档,所有示例都是关于 Playground 中的查询。现在我对使用 auth 中间件的概念感到困惑。我现在可以在我的商店操作中登录我的用户:NuxtJs
Apollo
vuex
GraphiQL
async loginUser ({ commit }, payload) {
try {
let client = this.app.apolloProvider.defaultClient
const LOGIN_USER = gql`
mutation tokenAuth($username: String! , $password: String!) {
tokenAuth(
username: $username,
password: $password,
) {
token
}
}
`
const { response } = await client.mutate({
mutation: LOGIN_USER,
variables: {
username: payload.username,
password: payload.password,
},
}).then(response =>{
commit('setAnUser', response.data)
})
return response
} catch (error) {
commit('setError', error)
}
},
所以回复我的查询:
{
"data": {
"tokenAuth": {
"success": true,
"errors": null,
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6Inl0c2VqYW0iLCJleHAiOjE2MTE1OTA3ODQsIm9yaWdJYXQiOjE2MTE1OTA0ODR9.P8Inn94AVUIyT8rQ_-VdxecDgOqT2NK7h1Y_16uxtfs",
"refreshToken": "f8143d09182ccf2a31aec5d7f9c53d0966260f63",
"user": {
"username": "ytsejam"
}
}
}
我nuxt.config.js
的如下:
现在我想不出一个策略如何使用我的回复nuxt.config.js
来验证检查。如何使用它来自定义我的导航,例如:User
token
<navbar>
<ul>
...
<div v-if="$auth.loggedIn">
<nuxt-link to="logout"> logout </nuxt-link>
</div>
....
</ul>
</navbar>
你能指导我吗?谢谢