D
D
devilsD2018-08-01 21:24:38
User identification
devilsD, 2018-08-01 21:24:38

Explain the logic of auth using nuxt auth as an example?

How to connect and send requests to the server - figured it out. I can't understand the logic, there are 3 query points in the config:

auth: {
    strategies: {
      lendpoints: {
      login: { url: '/api/login/', method: 'post', propertyName: 'token' },
      logout: { url: '/api/auth/logout', method: 'post' },
     user: { url: '/api/user/', method: 'get', propertyName: 'user' }
     },
 
      }
    }
  },

I send a request
return this.$auth
            .loginWith('local', 
            {
             data:   qs.stringify({
                login: 'admin',
                password: '123456'
            })
            }
            ).then(() => {
          alert('Logged In!')
        })
,
with the login and password parameters, I find the user on the server. This is where I hit a dead end. It is not clear to me:
what is the /api/login/ request for and what should it return.
what the /api/user/ request should return
, how can I check, for example, the username and the very fact of the user's authorization.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fedor Grebennikov, 2018-08-05
@devilsD

  1. The /api/login/ request expects a user token in response. How to select a token from the response is indicated in the auth settings. Those. the server receives login and the password, checks. If they are correct, it selects the token of this user from the database and returns it.
  2. After nuxt receives a token, it is stored in localStorage and, it seems, is duplicated in cookies
  3. This token then needs to be added to the header with each request and checked on the server
  4. /api/user/ is requested after the token and the user profile must be given in response
  5. If the profile is received, it is stored in the store and the loggedIn variable is set to true for the user
  6. That's it, the user is logged in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question