Jwt-auth: Fetch only required columns when authenticating

Created on 10 Jun 2016  路  3Comments  路  Source: tymondesigns/jwt-auth

When sending in a token , and monitoring the db query, I see:
select * fromuserswhereusers.id= '1' limit 1;

Is there a way for it to just load just certain columns (I have them indexed and hope to use covering index) instead of the entire row ?

stale

Most helpful comment

Here's a slightly-outdated diagram if that helps. (IIRC it's only accurate to stock Laravel 5.2 & jwt-auth 1.0 pre-alpha, but the general idea is still right.)

jwt_diagram

All 3 comments

That behavior is controlled by Laravel's _user provider_, not by the jwt-auth library.

You _can_ modify the behavior by creating a custom provider. For more details, check out the official docs (Laravel 5.1, Laravel 5.2).

Here's a slightly-outdated diagram if that helps. (IIRC it's only accurate to stock Laravel 5.2 & jwt-auth 1.0 pre-alpha, but the general idea is still right.)

jwt_diagram

@tdhsmith , thanks for the diagram!
What I am doing at the moment , is , inside JWTAuth's authenticate function , I am preventing the library from calling byId(). This is what the function looks like now:

public function authenticate($token = false)
    {
        $id = $this->getPayload($token)->get('sub');

        $user = new User(); 
        $user->id = $id;  
        return $user;   

    }

Is there anything crazy wrong with this approach ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

therealmjk picture therealmjk  路  3Comments

marciomansur picture marciomansur  路  3Comments

lloy0076 picture lloy0076  路  3Comments

NaelsonBrasil picture NaelsonBrasil  路  3Comments

shah-newaz picture shah-newaz  路  3Comments