mardi 31 juillet 2018

Laravel passport allow only one user to log in?

I created an app with laravel & vuejs, for authentication i used laravel-passport. When i create new user and try log in browser returns this error.

POST http://127.0.0.1:8000/oauth/token 401 (Unauthorized)

but it only works for one user and only for that user, when log in using that doesn't return any error it works fine.

i create new user by following controller method

public function store(Request $request)
{
    $this->validate($request, [
        'name'=> 'required|max:120',
        'email'=> 'required|email|unique:users',
        'password'=> 'required|min:6'
    ]);
    return User::create([
    'name' => $request['name'],
    'email' => $request['email'],
    'password' => Hash::make($request['password']),
    ]);
}

and the log in method,

login(){
     var data = {
      username: this.user.email,
      password: this.user.password,
      client_id: 2,
      client_secret: 'wcw9GkgKMHXUnyZavawJWXgE3GhSubOADO6tKw99',
      grant_type: 'password'
    }
      this.$store.dispatch('login',data )
          .then( response =>{
            this.$router.push('dashboard');
          });
}

in store.js

login({ commit }, creds){
        commit(LOGIN);


        return new Promise((resolve) => {
            setTimeout(() =>{
                axios.post('/oauth/token', creds)
                .then((response) =>{
                    Vue.auth.setToken(response.data.access_token, response.data.expires_in + Date.now());
                    commit(LOGIN_SUCCESS);
                    alert(response.data.access_token)

                    axios.get('api/user', { headers: {"Authorization" : 'Bearer'+' '+response.data.access_token } })
                    .then( response =>{
                      console.log('success_(store.js)',response.data.id)
                      axios.post('api/role', { uid: response.data.id})
                      .then( response =>{
                         console.log('success_(store.js)',response.data["0"].name)
                         Vue.auth.setUserRole(response.data["0"].name);
                      })
                    })
                    .catch( response =>{
                       console.log('error_', response)
                    })
                    resolve();
                });
            }, 5000);               
        });
    }

any help ?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NYaT2I
via IFTTT

Aucun commentaire:

Enregistrer un commentaire