I' trying to build an API authentication, I defined a controller for it and there's another one for the web login. I configured 2 different auth in config/api, because there are 2 types of users, the ones that are going to be using the API and the other are the web users. This is the guards config:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'users-api' => [
'driver' => 'token',
'provider' => 'users-api',
],
'users' => [
'driver' => 'session',
'provider' => 'usuarios',
],
],
Thing is that whenever I try to access /api/login I get redirected to /login (which is the web view, this is how I defined the Route in the api.php routes file:
Route::group(['middleware' => ['auth:users-api']], function () {
Route::get('login','api\AuthenticationController@authenticate');
Route::get('register','api\AuthenticationController@register');
});
It happens when I use the middleware, I have tried calling it from the Controller construct like this:$this->middleware('auth:users-api');
But I still get redirected, if I comment that line or if I don't use the middleware in the routes file, I don't get redirected but I need it to specify which table the auth will use. If you need anything else to help me solve it, I'll gladly provide it. Thanks in advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire