Using the Frontend SDK
The following examples will cover some common use-cases for the hanko-frontend-sdk
instance returned by the register()
function, but please take a look into the frontend-sdk docs for details.
You can create a hanko-frontend-sdk
instance without having to register the web components as follows
Events
It is possible to bind callbacks to different custom events in use of the SDKs event listener functions. The callback function will be called when the event happens and an object will be passed in, containing event details.
Session created
Will be triggered after a session has been created and the user has completed possible additional steps (e.g. passkey registration or password recovery). It will also be triggered when the user logs in via another browser window. The event can be used to obtain the JWT.
Session Expired
Will be triggered when the session has expired, or when the session has been removed in another browser window, because the user has logged out, or deleted the account.
User Logged Out
Will be triggered, when the user actively logs out. In other browser windows, a “hanko-session-expired” event will be triggered at the same time.
User Deleted
Will be triggered when the user has deleted the account. In other browser windows, a hanko-session-expired
event will be triggered at the same time.
Common Operations
The SDK provides functions to simplify interaction with the Hanko API. Here are some common operations:
Get the session validity and JWT claims:
Retrieve the session token:
Get the user data:
Log out the user:
To learn how error handling works and what else you can do with SDK, take a look into the frontend-sdk docs.