nemo
nemo

Reputation: 151

Nuxt auth without the user endpoint

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);

Upvotes: 2

Views: 1412

Answers (1)

Mohsen
Mohsen

Reputation: 4235

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

Upvotes: 2

Related Questions