Get User Data
Each project presents unique requirements for user onboarding. In this guide you’ll learn to get user data from Hanko.
Getting user data on the Frontend
To access user data in your frontend application, use the hanko.getCurrent()
method from the
hanko-frontend-sdk
(also available via hanko-elements). To get the user claims
from the JWT, use the hanko.validateSession()
function.
Getting user data on the Backend
Getting user ID from the JWT
The Hanko API sends back a cookie upon successful authentication, which is then sent to the RP backend for each subsequent request. The cookie contains a JWT. One of the things we can get from this JWT is the user ID. We can use the jose library to decode the value of such a JWT:
Getting email from the JWT
In addition to the user ID, you can also fetch the current email address, including its verification status and whether it is set as the primary email.
You can refer to JWT Payload Content docs for more information on the JWT payload.
Get user data using the Hanko Admin API
The Hanko Admin API provides detailed information about the status, user management, metrics and more. In this example we will focus on
getting the data from a specific user.
To get data for a specific user, call the /users/{id}
endpoint of the Hanko Admin API, where id
is the user id previously obtained from the JWT.
The Hanko Admin API is available in Hanko Pro and Enterprise plans. Check out our pricing page for more information.
You also need an API key secret to access the Hanko Admin API which can be
generated under the Settings > API Keys
section of your project.