Nuxt auth without the user endpoint

1.3k Views Asked by At

I'm using Nuxt auth, but I don't have an endpoint for the user, in nuxt.config is set the endpoint to be false and after loginWith I'm jest setting the user manually.

The issue is that after refresh I'm logged in but I don't have any user info (name, email...) what I'm I missing here?

nuxt.config file:

  auth: {
    strategies: {
      local: {
        endpoints: {
          login: {
            url: '/api/users/login/',
            method: 'post',
            propertyName: 'token',
          },
          logout: { url: '/api/users/logout/', method: 'post' },
          user: { url: '/api/users/auth/', method: 'post' },
          // user: false,
        },
        autoFetchUser: false,
        tokenName: 'Authorization',
        tokenType: 'Token',
        // tokenRequired: true,
        // globalToken: true,
      },
    },
  },

login form file

     const { data } = await this.$auth.loginWith('local', {
          data: { username: this.email, password: this.password },
        });
        this.$auth.setUser(data);
1

There are 1 best solutions below

2
On

When you logged in, user info will return from login data, when you refresh there is no endpoint for user, then auth plugin cant retrieve your user info, so you must do it manually and setUser yourself