V
V
Vlad Volodko2019-05-24 00:15:58
Laravel
Vlad Volodko, 2019-05-24 00:15:58

Why VueJs&Laravel5 authorization fails?

Hello, there was such a problem that when authorizing through laravel passport, a 401 error is returned to me, but if I try to authorize again, then everything is OK
. I send a request with vuejs using axios, there is a token, it is transmitted correctly. but I can’t understand why this happens
UPD1 a little config.js code

const config = function(cook) {
  return {
    baseURL: API_URL,
    headers: {
      Accept: 'application/json',
      Authorization:  `Bearer ${cook}`
    }
  }
}

The method I'm calling
const getEnrollList = (role) => {
  let url = ''
  url = role == 'master' ? '/master/getEnrollList' : '/client/getEnrollList'
  return API.get(url, { 
    params: {
      hash: Cookie.get('salon')
    },
    headers: { 
      Authorization:  `Bearer ${Cookie.get('token')}`
    } 
  }).catch( (response, error) => {
    window.location.href = '/'
  })
}

backend
Route::group(['middleware' => ['web','auth:api']], function() {

Route::get('getEnrollList', 'Client\[email protected]');

// Роутер для клиента
    Route::group(['prefix' => 'client', 'middleware' => 'client'], function () {
        Route::get('getEnrollList', 'Client\[email protected]');
    });

    // Роутер для мастера
    Route::group(['prefix' => 'master', 'middleware' => 'master'], function () {
        Route::get('getEnrollList', 'Master\[email protected]');
    });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2019-05-24
@jazzus

Try get on the post request to edit. Both in Laravel in routes and in vue in sending. And there is no such thing in the master / client urls in the route group. You can give a name to the route and pass the correct url from Laravel to props vue via route('name')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question