Get user data from API

To access user data in your frontend application, use the hanko.getUser() method from the hanko-frontend-sdk (also available via hanko-elements).
import { Hanko } from "@teamhanko/hanko-elements";

const hankoApi = "<YOUR_HANKO_API_URL>";
const hanko = new Hanko(hankoApi);

// Fetches the current user's profile information
const user = await hanko.getUser();
console.log("User profile:", user);
// Example output:
// {
//   user_id: "123e4567-e89b-12d3-a456-426614174000",
//   emails: [{ address: "user@example.com", is_primary: true, is_verified: true }],
//   username: { id: "f2882293-3c39-451d-a7cb-4cf3375e0c66", username: "johndoe" },
//   created_at: "2025-01-01T10:00:00Z",
//   updated_at: "2025-04-01T12:00:00Z"
// }
To extract user claims from the JWT token, use the hanko.validateSession() function.
import { Hanko } from "@teamhanko/hanko-elements";

const hankoApi = "<YOUR_HANKO_API_URL>";
const hanko = new Hanko(hankoApi);

// Checks the validity of the current session and returns the user claims
const sessionStatus = await hanko.validateSession();
console.log("Session status:", sessionStatus);
// Example output:
// {
//   is_valid: true,
//   claims: {
//     subject: "123e4567-e89b-12d3-a456-426614174000",
//     session_id: "789abc",
//     expiration: "2025-04-25T12:00:00Z",
//     email: { address: "user@example.com", is_primary: true, is_verified: true },
//     custom_field: "value"
//   }
// }