mercredi 30 mars 2016

Laravel JWT Auth fetch user if token

I'm using the jwt-auth package for Laravel. It's working great, but it seems that a user has to be authenticated or not.

For instance some routes do not require authentication, but if the token is present it should still authenticate the user. The parameters I display to user from API can vary based on the type of users access. So admins will get some additional parameters.

Right now it will always just throw token absent. But it should go through as normal and "IF" token is present, process it.

Not sure if I need to create a custom middleware for this.

class JWTAuthIfPresent
{
    public function handle($request, Closure $next)
    {
        if (JWTAuth::getToken()) {
            JWTAuth::parseToken()->authenticate();
        }

        return $next($request);
    }
}

This seems to work, but not sure if there is a better way or something already in the existing package.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1RKkNiC
via IFTTT

Aucun commentaire:

Enregistrer un commentaire