如何在 nuxt/auth 中设置用户

时间:2021-07-06 03:35:46

标签: nuxt.js nuxt-auth

我将 autoFetchUser 设置为 false nuxt.config.js

auth: {
    redirect: {
      login: '/',
      logout: '/',
      home: '/account',
    },
    strategies: {
      local: {
        token: {
          required: false,
          type: false,
        },
        user: {
          autoFetch: false,
        },
        endpoints: {
          login: {
            url: '/api-url/oauth/sign_in',
            method: 'post',
            propertyName: 'data.user.access_token',
          },
          logout: { url: '/api-url/oauth/revoke', method: 'post' },
          user: false,
        },
      },
    },

然后在登录时我设置了用户手册 login page

this.$auth
        .loginWith('local', {
          data: {
            phone: this.phone,
            password: this.password,
            latlong: '0.0,0.0',
            device_token: '',
            device_type: 2,
          },
        })
        .then(async (resp) => {
          console.log(resp, 'RESP')
          await this.$auth
            .fetchUser({
              params: { access_token: resp.data.data.user.access_token },
            })
            .then((user) => {
              console.log('USER', user.data)
              this.$auth.setUser(user.data.user)
              this.$auth.setUserToken(resp.data.data.user.access_token)
            })
        })

页面重定向到/account, 并且调用了console.log RESP,但是没有调用获取和设置用户的函数

并且在登录后的页面中,我打印的 $auth.user 为空 profile page

如何在nuxt/auth登录时手动设置用户

0 个答案:

没有答案