Overview
In the following steps, we will guide you on how to integrate Corbado into your frontend.
1. Install dependencies
When cloning the example, all dependencies are already set up, and you just need to run:
If you start from scratch you need to install the corbado_auth
Package:
2. Initialize Corbado
First, we need to set up the Corbado provider. The provider setup should be placed in a dedicated provider file:
Next, we need to initialize CorbadoAuth and configure the provider:
Configuration Options
Field | Type | Default | Description |
---|---|---|---|
projectId | String | - | Your Corbado project ID |
debugMode | bool? | false | Enables our doctor tool to help debug and troubleshoot your passkey integration |
telemetryDisabled | bool? | false | Disables telemetry events |
telemetryDebugModeEnabled | bool? | false | Prints telemetry events to console instead of sending them |
Ensure the provider is correctly initialized within your app’s state management solution, such as Riverpod.
3. Implement authentication flow
We use a provider to handle authentication state and access user information:
To manage user navigation, we need to set up routing that is aware of authentication status. Here is an example using go_router:
Corbado’s authentication flow requires handling user navigation based on authentication state. The routing configuration ensures that:
- Unauthenticated users are redirected to the authentication screen (
/auth
). - Authenticated users are redirected to the profile screen (
/profile
). - Users cannot access restricted pages unless they are logged in.
The redirect logic ensures:
- If a user is not signed in and tries to access a protected route, they are sent to
/auth
. - If a user is already signed in but tries to access
/auth
, they are redirected to/profile
instead.
This behavior is handled within the redirect
function in the routing setup:
4. Create authentication screens
To display the authentication UI, CorbadoAuthComponent
is used, which internally manages authentication flows such as signup, login, and passkey handling. The corbadoAuth
provider is accessed using Riverpod:
The authentication screen is implemented using CorbadoAuthComponent
, handling user interactions:
After successful login, users are redirected to their profile. This page provides basic user information and allows users to sign out.
The profile screen can include:
- A welcome message displaying the authenticated user’s details.
- A sign-out button to log the user out and return to the authentication screen.
5. Handle Corbado screens
Corbado authentication is structured into multiple screens, each corresponding to a different part of the authentication flow. These screens are implemented using CorbadoScreen<T>
, where T
represents a supported Corbado block containing the required logic. Corbado automatically manages routing between these screens internally.
6. Set up Flutter Web
For Flutter web applications, include the Corbado JavaScript bundle in your index.html
: