How to change JWT payload in Laravel?

Asked

Viewed 41 times

0

I need to change my payload of my JWT to match the example below.

{
  "iat": 1566408228,
  "exp": 1566426828,
  "email": "[email protected]",
  "name": "Fulano Silva",
  "roles": [
    "manager"
  ]
}
  • 1

    If you use a package

1 answer

0


I was able to solve it this way:

Model User

use Tymon\JWTAuth\Contracts\JWTSubject;

// Meu model agora implementa o JWTSubject
class User extends Authenticatable implements JWTSubject{

    // Adicionei essa função
    public function getJWTCustomClaims()
    {
        return [
            'id' => $this->id,
            'email' => $this->email,
            'name' => $this->name,
        ];
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.