Skip to content

Commit 45cb87a

Browse files
authored
Merge pull request #214 from okto-hq/main
onboarding screen pages
2 parents 6b2a48d + 0fab084 commit 45cb87a

File tree

18 files changed

+684
-70
lines changed

18 files changed

+684
-70
lines changed

content/docs/flutter-sdk/advanced-sdk-config/authenticate-users/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"google-oauth",
66
"phone-otp",
77
"email-otp",
8+
"onboarding-modal",
89
"!other-social-auth",
910
"login-logout"
1011
]
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
title: Authenticate User via Onboarding Modal
3+
description: Learn how to trigger and handle authentication using the Okto Onboarding Modal.
4+
full: false
5+
---
6+
7+
import { TypeTable } from 'fumadocs-ui/components/type-table';
8+
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
9+
import { Callout } from 'fumadocs-ui/components/callout';
10+
import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
11+
import { Icon as IIcon } from '@iconify/react';
12+
13+
import '../../../styles.css';
14+
15+
### Methods Overview
16+
17+
| Method | Description |
18+
|----------------------------------|------------------------------------------------------------------------------------------------------|
19+
| <sub><i>async</i></sub>[`openOnboarding`](#show-onboarding-modal) | Opens the Okto Onboarding flow with your chosen primaryAuth (e.g., Email, Phone, or Google) and brand data |
20+
21+
<div class="method-box">
22+
23+
## Show Onboarding Modal
24+
25+
`openOnboarding(...)` <a href="https://github.com/okto-hq/okto-sdk-flutter/blob/main/lib/src/okto.dart#L350" target="_blank" rel="noopener noreferrer" style={{ textDecoration: 'none' }}><IIcon icon="lucide:external-link" height="17" style={{ display: 'inline-block', verticalAlign: 'middle' }} /></a> presents a guided onboarding flow to the user. This includes brand data, theming, and whichever `primaryAuth` type you’ve set in the `openOnboarding()` parameters. Under the hood, it launches a **WebView** that takes the user through various authentication options (Email OTP, Phone OTP, Google OAuth, etc.).
26+
27+
### Parameters
28+
29+
| Parameter | Type | Description |
30+
|-----------------------|-------------------------------|-----------------------------------------------------------------------------|
31+
| `context` | `BuildContext` | The Flutter build context. *(Required)* |
32+
| `gAuthCallback` | `Future<String> Function()` | A function that returns a Google **ID token** (if using `AuthType.GAUTH`). |
33+
| `onLoginSuccess` | `Function` | Callback triggered once the user completes onboarding successfully. |
34+
| `primaryAuth` | `AuthType` | Set your default authentication flow. E.g. `AuthType.EMAIL`, `AuthType.PHONE`, `AuthType.GAUTH`. |
35+
| `title` | `String` | A title for brand customization (optional). |
36+
| `iconUrl` | `String` | A brand icon URL (optional). |
37+
| `subtitle` | `String` | A subtitle for brand customization (optional). |
38+
| Theming parameters | `String` (color in hex) | Additional theming (text colors, background, accent, etc.). |
39+
40+
### Response
41+
42+
<Callout title="Success Response">
43+
44+
| Field Name | Type | Description |
45+
|------------|------------------|--------------------------------------------|
46+
| `result` | `Future<void>` | Returns no meaningful response on success. |
47+
48+
</Callout>
49+
50+
<Accordions>
51+
<Accordion title="Example">
52+
<Tabs items={['Typescript']}>
53+
<Tab value="Typescript">
54+
55+
```typescript
56+
import 'package:flutter/material.dart';
57+
import 'package:okto_flutter_sdk/okto_flutter_sdk.dart';
58+
59+
class OnboardingModalExample extends StatefulWidget {
60+
const OnboardingModalExample({Key? key}) : super(key: key);
61+
62+
@override
63+
_OnboardingModalExampleState createState() => _OnboardingModalExampleState();
64+
}
65+
66+
class _OnboardingModalExampleState extends State<OnboardingModalExample> {
67+
final Okto okto = Okto(); // Initialize Okto instance
68+
String _message = '';
69+
70+
Future<void> _handleOnboarding() async {
71+
try {
72+
await okto.openOnboarding(
73+
context: context,
74+
gAuthCallback: _googleAuthCallback, // Returns Google ID token if using Google
75+
primaryAuth: AuthType.EMAIL, // Default to Email OTP
76+
title: "Your App Name",
77+
subtitle: "Welcome to Web3",
78+
iconUrl: "https://your-app.com/icon.png",
79+
textPrimaryColor: '0xFFFFFFFF',
80+
textSecondaryColor: '0xFFCCCCCC',
81+
accent1Color: '0xFF905BF5',
82+
backgroundColor: '0xFF000000',
83+
);
84+
setState(() {
85+
_message = 'Onboarding completed successfully!';
86+
});
87+
} catch (error) {
88+
setState(() {
89+
_message = 'Error during onboarding: $error';
90+
});
91+
}
92+
}
93+
94+
Future<String> _googleAuthCallback() async {
95+
// If using Google Sign-In:
96+
// final GoogleSignIn googleSignIn = GoogleSignIn(...);
97+
// final user = await googleSignIn.signIn();
98+
// final auth = await user?.authentication;
99+
// return auth?.idToken ?? "";
100+
return ""; // Return "" if you don't have Google set up
101+
}
102+
103+
@override
104+
Widget build(BuildContext context) {
105+
return Scaffold(
106+
appBar: AppBar(
107+
title: const Text('Onboarding Modal Example'),
108+
),
109+
body: Padding(
110+
padding: const EdgeInsets.all(16),
111+
child: Column(
112+
children: [
113+
ElevatedButton(
114+
onPressed: _handleOnboarding,
115+
child: const Text('Launch Onboarding Modal'),
116+
),
117+
const SizedBox(height: 16),
118+
Text(_message),
119+
],
120+
),
121+
),
122+
);
123+
}
124+
}
125+
```
126+
127+
</Tab>
128+
</Tabs>
129+
</Accordion>
130+
</Accordions>
131+
132+
</div>
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
---
2+
title: Learn
3+
description: Learn how the Okto Onboarding Modal helps streamline user authentication and onboarding workflows in Flutter apps.
4+
full: false
5+
---
6+
7+
import { Callout } from 'fumadocs-ui/components/callout';
8+
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
9+
10+
# What is the Onboarding Modal?
11+
12+
Okto’s **Onboarding Modal** provides a **streamlined** way to authenticate users by displaying an embeddable flow (via a **WebView**) without requiring them to leave your **Flutter** app. Under the hood, the **Onboarding Modal** can handle multiple authentication flows (Email OTP, Phone OTP, Google OAuth, etc.) and can be customized with brand data, visuals, and theming.
13+
14+
## Why Use the Onboarding Modal?
15+
16+
1. **No Authentication Flow Management**
17+
Vendors need not work or worry about the authentication flow or the code for it. Okto handles everything on the server side, simplifying the implementation and saving development time.
18+
19+
2. **Multi-Auth Support**
20+
The modal can be set up to handle Google Auth, Email OTP, Phone OTP, or your primary authentication of choice.
21+
22+
3. **Brand & Theme Customizations**
23+
Pass your branding (title, subtitle, icon) and theming (colors, backgrounds, etc.) to tailor the onboarding experience to your style guidelines.
24+
25+
## Typical Flow
26+
27+
Below is a simplified sequence for how the Onboarding Modal works:
28+
29+
1. **Trigger the Modal**
30+
Your Flutter code calls `okto.openOnboarding(...)` from the **Okto** SDK. This opens a new **Onboarding** page containing a WebView.
31+
32+
2. **WebView Initialization**
33+
The WebView loads the Okto environment for your selected `buildType` (Sandbox, Staging, or Production).
34+
It also receives your brand data, theming, and selected primary authentication method.
35+
36+
3. **User Authentication**
37+
The user completes the steps (e.g., Google login, Email OTP, or Phone OTP). If the flow requires an external token (like a Google ID token), Okto can request it from your Flutter app via `gAuthCallback()`.
38+
39+
4. **Auth Success**
40+
Once the user is authenticated, Okto returns the relevant tokens (`authToken`, `refreshToken`, etc.) and closes the onboarding screen automatically. At that point, your Flutter app can continue with a fully authenticated user.
41+
42+
### Sequence Diagram
43+
44+
![Auth Sequence Diagram](/images/onboarding-modal-sequence-diagram.png)
45+
46+
## Key Points to Remember
47+
48+
- **`showOnboardingModal()`** in the SDK is your main entry point to launch the modal.
49+
- You can customize brand data, theming, and the primary auth method (Email, Phone, or Google).
50+
- For Google OAuth, provide a callback (`gAuthCallback`) that returns an ID token from your chosen sign-in flow (e.g., `google_sign_in` package).
51+
- On success, your app will have the user’s `authToken` (and refresh token) stored in Okto’s internal state.
52+
53+
---
54+
55+
# Enabling Google Authentication in the Onboarding Modal
56+
57+
Okto’s Onboarding Modal can integrate with **Google Authentication** to offer a smooth, single-click login experience. To enable this, you need to configure the `gAuthCallback`, which handles the retrieval of your Google ID token. Below is an example using the `google_sign_in` package.
58+
59+
**Example `login_page.dart` snippet:**
60+
61+
```dart
62+
import 'package:google_sign_in/google_sign_in.dart';
63+
import 'package:example/okto.dart'; // or your own utils
64+
import 'package:flutter/material.dart';
65+
import '../screens/home/home_page.dart';
66+
67+
class LoginPage extends StatefulWidget {
68+
const LoginPage({super.key});
69+
70+
@override
71+
State<LoginPage> createState() => _LoginPageState();
72+
}
73+
74+
class _LoginPageState extends State<LoginPage> {
75+
@override
76+
Widget build(BuildContext context) {
77+
return Scaffold(
78+
backgroundColor: const Color(0xff5166EE),
79+
body: SafeArea(
80+
child: Column(
81+
children: [
82+
// ... other login methods here ...
83+
ElevatedButton(
84+
onPressed: () async {
85+
// This uses the Okto Onboarding flow with a callback for Google sign-in
86+
await okto!.openOnboarding(
87+
context: context,
88+
gAuthCallback: _loginWithGoogle,
89+
onLoginSuccess: _handleLoginSuccess,
90+
primaryAuth: AuthType.GAuth, // sets Google as the primary
91+
title: "My Flutter App",
92+
iconUrl: "https://example.com/icon.png",
93+
subtitle: "Welcome to Web3 with Okto",
94+
);
95+
},
96+
child: const Text('Onboarding (Google)'),
97+
),
98+
],
99+
),
100+
),
101+
);
102+
}
103+
104+
Future<String> _loginWithGoogle() async {
105+
final GoogleSignIn googleSignIn = GoogleSignIn(
106+
scopes: [
107+
'email',
108+
'https://www.googleapis.com/auth/userinfo.profile',
109+
'openid',
110+
],
111+
);
112+
try {
113+
final user = await googleSignIn.signIn();
114+
final auth = await user?.authentication;
115+
if (auth == null) return "";
116+
return auth.idToken ?? "";
117+
} catch (e) {
118+
debugPrint("GAuth Error: $e");
119+
return "";
120+
}
121+
}
122+
123+
void _handleLoginSuccess() {
124+
// Optionally, navigate or show a toast
125+
Navigator.pushReplacement(
126+
context,
127+
MaterialPageRoute(builder: (context) => const HomePage()),
128+
);
129+
}
130+
}
131+
132+
```
133+
134+
**Key Steps:**
135+
136+
- The callback `_loginWithGoogle` returns a Google ID token (or empty on error).
137+
- Okto uses this token to complete the Google auth process.
138+
- On success, `onLoginSuccess` is called, and your user is now fully authenticated.
139+
140+
## Common Tips & FAQ
141+
142+
- **Custom Branding:** Okto’s `openOnboarding(...)` lets you pass `title`, `subtitle`, `iconUrl` plus color theming to customize the look.
143+
144+
- **Primary Auth Method:** By default, you can set `primaryAuth: AuthType.GAuth` (Google), `AuthType.EMAIL`, or `AuthType.PHONE`. You can also override it dynamically if needed.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"title": "Onboarding Modal",
3+
"pages": [
4+
"learn",
5+
"auth-user-via-modal"
6+
]
7+
}

content/docs/flutter-sdk/advanced-sdk-config/okto-embedded-wallet/built-in-ui-screens/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"title": "Built in UI Screens",
33
"pages": [
44
"!learn-okto-ui-screens",
5-
"!onboarding-screen",
5+
"[Onboarding Modal](/docs/flutter-sdk/advanced-sdk-config/authenticate-users/onboarding-modal/learn)",
66
"!portfolio-screen",
77
"!activity-screen",
88
"show-ui-screen-via-code",

content/docs/react-native-sdk/advanced-sdk-config/authenticate-users/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"google-oauth",
66
"phone-otp",
77
"email-otp",
8+
"onboarding-modal",
89
"!other-social-auth",
910
"login-logout"
1011
]

0 commit comments

Comments
 (0)