1. Install dependencies
When cloning the example, all dependencies are already set up, and you just need to run: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:lib/auth_provider.dart
lib/main.dart
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 |
For more details about telemetry, please refer to our telemetry documentation.
3. Implement authentication flow
We use a provider to handle authentication state and access user information:lib/auth_provider.dart
lib/auth_provider.dart
lib/router.dart
- 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.
- 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/profileinstead.
redirect function in the routing setup:
lib/router.dart
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:
lib/pages/auth_page.dart
CorbadoAuthComponent, handling user interactions:
lib/pages/auth_page.dart
- 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 usingCorbadoScreen<T>, where T represents a supported Corbado block containing the required logic. Corbado automatically manages routing between these screens internally.
For a deeper understanding of how these blocks work, we will go through each in the next Step.
6. Set up Flutter Web
For Flutter web applications, include the Corbado JavaScript bundle in yourindex.html:
web/index.html
Check the index.html example for reference.