mardi 2 juillet 2019

Auth::user(); doesn't returns users, using passport

I have situation about returning users from DB. In my controller I am trying it like below.

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;

class UsersController extends Controller
{
    public function getUser(){

        $users = Auth::user();
        dd($users);
    }
}

And about the api route:

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

    Route::post("logout", "Api\AuthController@logout");

    /* User */

    Route::get('/user', 'Api\UsersController@getUser');

});


Route::group(["prefix" => "v1"], function(){

    /* Auth */
    Route::post("login", "Api\AuthController@login")->name("login");
    Route::post("register", "Api\AuthController@register");

});

Here is the thing. If I use my UserController route outside the middleware:api then endpoint is returns null. And if use it inside the middleware it redirects me to my login's endpoint. Because of the "->name()"

In the end I can't return the users. Additionally this is what config/auth looks like.

'defaults' => [
    'guard' => 'web',
    'passwords' => 'users',
],

By the way before asked. I tried to change guard's web to api but nothing is changed.

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
        // 'hash' => false,
    ],
],



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

Aucun commentaire:

Enregistrer un commentaire