Understand how Hanko’s Flow API streamlines your authentication frontend code by shifting state-driven flow logic to the backend. Learn how to initialize and interact with flows, manage validation and technical errors, and tailor flow configurations to fit your application’s needs.
hanko-frontend-sdk
are the tools you need for that.
The Flow API simplifies frontend development by moving authentication flow logic to the backend. Traditional authentication implementations require frontends to manage complex state transitions, predict next steps, and handle various configuration options. This complexity increases maintenance overhead and makes configuration changes difficult.
The Flow API solves this by maintaining all authentication state on the backend. Your frontend only needs to render the current state and execute available actions, without tracking user inputs or predicting what comes next.
Key takeaways include:
state
in the authentication flow, and each state defines available actions
that users can perform.
Your frontend implementation requires a handler function for each possible state. When you receive a new response from the backend, the corresponding handler processes it and renders the UI based on the available actions.
Each action includes:
payload
with additional data specific to that state, such as user information or configuration details needed for UI rendering.
The diagram shows the structure of a flow response:
POST
request:
/login
- User authentication flow/registration
- User registration flow/profile
- User profile management flow/example-flow
endpoint to demonstrate the concepts. Here’s how to initialize and work with any flow:
Initialize a new flow
POST
request to the the flow URL, /example-flow
in this example.Obtain the response body
Generate the request object
csrf_token
from the previous state must be included in each request.Execute the action
POST
request to the href
provided by the action. In this case, the href
is
/example-flow?action=example-action@example-flow-id
.Obtain the response body
min_length
and max_length
). While you can implement client-side validation using this metadata, the backend always performs final validation and returns detailed error information when validation fails:
Send invalid input values
Execute the action
POST
request to the href
provided by the action. Again, the href
would be
/example-flow?action=example-action@example-flow-id
.Obtain the response body
status
field has changed to ‘400’ (Bad Request), indicating that the request was invalid. A
global error object has been added with the code
‘form_data_invalid_error’ and the message
‘Form data invalid’. Additionally, the invalid input field now includes an error object with the code
‘value_too_short_error’, and the message
‘The value is too short’.