Skip to content

Adding payload to the JWT #98

Answered by eschricker
dan-lutd asked this question in Q&A
Discussion options

You must be logged in to vote

I am not sure if its meant to be used in this way or if there are any side effects, but you could try the following:

use PHPOpenSourceSaver\JWTAuth\JWT;

...

public function login(JWT $jwt, Request $request)
{
    $credentials = $request->only(['email', 'password']);

    $deviceId = $request->input('device_id');

    $jwt->getPayloadFactory()->deviceId($deviceId);

    if (!$token = Auth::attempt($credentials)) {
        return response()->json(['error' => 'Unauthorized'], 401);
    }

    return $this->respondWithToken($token);
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dan-lutd
Comment options

Answer selected by eschricker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants