Search code examples
laravelauthenticationjwtpostman

Find id of user with JWT token in laravel


In my API after the user registers, a token is created with this code :

$token = JWTAuth::fromUser($user);

when I use dd($token), returns this :

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9sb2dpbiIsImlhdCI6MTYyNjgxNDM2NCwiZXhwIjoxNjI2ODE3OTY0LCJuYmYiOjE2MjY4MTQzNjQsImp0aSI6Imd3eDZnVzNGTGN4MzlMekIiLCJzdWIiOjQsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ._m-7tojFaupUbAibDUbLJm6BeuFVL_etdFlwj0h5664

So how can I find the id of user without entering this token in authorization of postman?


Solution

  • Simple, use https://jwt.io

    In "sub" (subject) you will see the user id.

    enter image description here

    Read more about jwt tokens