Laravel , how to get loggedin user from jwt token

  api, jwt, laravel, php

I have created an authentication with JWT in custom table. Authentication works fine, i am able to login and token is generated with success. The problem is not being able to get the information like ‘id’ etc FROM the generated TOKEN of the custom table.

    $token = $request->header('Authorization');
    $user = JWTAuth::toUser($token);
    return $user;

Returned information are form the ‘user‘ table not from the custom table used for the jwt authenticaiton.
My configration looks like

    'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => AppModelsUser::class,
    ],

    'partners_credentials' => [
        'driver' => 'eloquent',
        'table' => 'partners_credentials',
        'model' => AppModelsPartnerCredentials::class,
    ],
],

Guards

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

    'partners_credentials' => [
        'driver' => 'session',
        'provider' => 'partners_credentials',
        'hash' => false,
    ],
],

What i am missing here

Source: Laravel

Leave a Reply