Constructor
# new Hanko(api, optionsopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
api |
string
|
The URL of your Hanko API instance | |
options |
HankoOptions
|
<optional> |
The options that can be used |
Extends
Members
Methods
# createState(flowName, configopt) → {Promise.<AnyState>}
Creates a new flow state for the specified flow.
This method initializes a state by either loading from cache (if configured) or fetching from the server.
It uses the provided configuration to control caching, event dispatching, and auto-step behavior.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
flowName |
FlowName
|
The name of the flow to create a state for. | ||
config |
StateCreateConfig
|
<optional> |
{} | Configuration options for state creation. |
dispatchAfterStateChangeEvent |
boolean
|
<optional> |
true | Whether to dispatch an event after the state changes. |
excludeAutoSteps |
AutoStepExclusion
|
<optional> |
null | States to exclude from auto-step processing, or `"all"` to skip all auto-steps. |
cacheKey |
string
|
<optional> |
"hanko-flow-state" | Key used for caching the state in localStorage. |
loadFromCache |
boolean
|
<optional> |
true | Whether to attempt loading the state from cache. |
A promise that resolves to the created flow state.
Promise.<AnyState>
# getSessionToken() → {string}
Retrieves the current session token from the authentication cookie.
The session token
string
# async getUser() → {Promise.<User>}
Retrieves the current user's profile information.
If the user is not authenticated
If an unexpected error occurs
A promise that resolves to the user object
Promise.<User>
# async logout() → {Promise.<void>}
Logs out the current user by invalidating the session.
A promise that resolves when the logout is complete
Promise.<void>
# onSessionCreated(callback, onceopt) → {CleanupFunc}
Adds an event listener for "hanko-session-created" events. Will be triggered across all browser windows, when the user
logs in, or when the page has been loaded or refreshed and there is a valid session.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
CallbackFunc.<SessionDetail>
|
The function to be called when the event is triggered. | |
once |
boolean
|
<optional> |
Whether the event listener should be removed after being called once. |
This function can be called to remove the event listener.
# onSessionExpired(callback, onceopt) → {CleanupFunc}
Adds an event listener for "hanko-session-expired" events. The event will be triggered across all browser windows
as soon as the current JWT expires or the user logs out. It also triggers, when the user deletes the account in
another window.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
CallbackFunc.<null>
|
The function to be called when the event is triggered. | |
once |
boolean
|
<optional> |
Whether the event listener should be removed after being called once. |
This function can be called to remove the event listener.
# onUserDeleted(callback, onceopt) → {CleanupFunc}
Adds an event listener for hanko-user-deleted events. The event triggers, when the user has deleted the account.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
CallbackFunc.<null>
|
The function to be called when the event is triggered. | |
once |
boolean
|
<optional> |
Whether the event listener should be removed after being called once. |
This function can be called to remove the event listener.
# onUserLoggedOut(callback, onceopt) → {CleanupFunc}
Adds an event listener for hanko-user-deleted events. The event triggers, when the user has deleted the account in
the browser window where the deletion happened.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
CallbackFunc.<null>
|
The function to be called when the event is triggered. | |
once |
boolean
|
<optional> |
Whether the event listener should be removed after being called once. |
This function can be called to remove the event listener.
# setLang(lang)
Sets the preferred language on the underlying sub-clients. The clients'
base HttpClient uses this language to transmit an X-Language header to the
API which is then used to e.g. translate outgoing emails.
Parameters:
Name | Type | Description |
---|---|---|
lang |
string
|
The preferred language to convey to the API. |
# async validateSession() → {Promise.<SessionCheckResponse>}
Validates the current session.
A promise that resolves to the session check response
Promise.<SessionCheckResponse>