API Documentation
Public
- Introduction
- Flow
- Status
- Passcode
- Password
- WebAuthn
- .well-known
- Third Party
- Token
- User Management
- Email Management
- SAML
- Session Management
Admin
- Introduction
- Status
- User Management
- User Metadata Management
- Email Management
- Password Management
- WebAuthn credential Management
- OTP Management
- Session Management
- Webhooks
- Audit Logs
- Metrics
Public
Learn how to use the Hanko Public API
This minimal example showcases how you can get user data using Public API from the userID obtained from the JWT.
import { cookies } from "next/headers";
import * as jose from "jose";
const hankoApiUrl = process.env.NEXT_PUBLIC_HANKO_API_URL;
export async function getUserData() {
const token = cookies().get("hanko")?.value;
const payload = jose.decodeJwt(token ?? "");
const userID = payload.sub;
const response = await fetch(`${hankoApiUrl}/users/${userID}`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (!response.ok) {
return null;
}
const userData = await response.json();
return userData;
}
Was this page helpful?
Assistant
Responses are generated using AI and may contain mistakes.