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.
Sessions
Determine whether the user is logged in
Getting the session details
User Client
The SDK contains several client classes to make the communication with the Hanko-API easier. Here some examples of things you might want to do
Getting the current user
Log out a user
To learn how error handling works and what else you can do with SDK, take a look into the frontend-sdk docs.
Was this page helpful?