0

我将 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,
        },
      },
    },

然后在登录中我设置用户手动 登录页面

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的是空 的个人资料页面

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

4

0 回答 0