Learn
Learn how the Okto Onboarding Modal helps streamline user authentication and onboarding workflows.
What is the Onboarding Modal?
Okto’s Onboarding Modal provides a streamlined way to authenticate users by displaying an embeddable flow (via an iframe) without requiring them to leave your React 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.
Why Use the Onboarding Modal?
-
No Authentication Flow Management
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. -
Multi-Auth Support
The modal can be set up to handle Google Auth, Email OTP, Phone OTP, or your primary authentication of choice. -
Brand & Theme Customizations
Pass your branding (title, subtitle, icon) and theming (colors, backgrounds, etc.) to tailor the onboarding experience to your style guidelines.
Typical Flow
Below is a simplified sequence for how the Onboarding Modal works:
-
Trigger the Modal
Your React app callsshowOnboardingModal()
from the Okto SDK. This opens a modal containing an iframe. -
Iframe Initialization
The iframe loads the Okto environment for your selectedBuildType
(Sandbox, Staging, or Production).
It also receives your brand data, theming, and selected primary authentication method. -
User Authentication
The user proceeds to completes the steps (e.g., Google login, Email OTP, or Phone OTP). If the flow requires an external token (like Google ID token), the modal can request it from your app viagAuthCb()
. -
Auth Success
Once the user is authenticated, Okto returns the relevant tokens (authToken
,refreshToken
, etc.) and closes the modal automatically.
Sequence Diagram
Key Points to Remember
showOnboardingModal()
in the SDK is your main entry point to launch the modal.- You can customize brand data, theming, and the primary auth method (Email, Phone, or Google).
- For Google OAuth, provide a callback (
gAuthCb
) to exchange the OAuth code for an ID token—or return an ID token directly if you have it. - On success, your app will have the user’s
authToken
(and refresh token) stored in Okto’s internal state.
Enabling Google Authentication in the Onboarding Modal
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 gAuthCb
callback, which handles the exchange of Google OAuth credentials for an ID token. The specifics depend on your framework/setup:
- React: Typically needs a server-side exchange (Authorization Code Flow).
- Next.js: Can often get an ID token directly using NextAuth or similar, without spinning up a separate backend.
Below, we’ll show both approaches.
React: Using a Separate Backend
If you have a standard Create React App (or similar), you usually cannot store the Google Client Secret in frontend code. This is why you need a small backend service to handle the secure OAuth code exchange.
Step 1: Google Cloud Setup
- Create a Google Cloud project.
- Enable OAuth consent screen and get a Client ID and Client Secret.
- Whitelist your app’s domain (if you’re in development,
http://localhost:3000
is typical).
Step 2: Set Up a Backend for Token Exchange
Since the Google Client Secret cannot be exposed in front-end code, you need a backend to securely exchange the authorization code for an ID token.
Backend Example (Node.js)
- Install Dependencies
Create a new folder for your backend and install the required packages:
- Create the Backend Server
Create a file named okto-gauth-server.js
and add the following code:
- Add Environment Variables
Create a .env
file in the backend folder and add your Google credentials:
- Run the Backend
Start the backend server:
Step 3: React Frontend + OktoProvider
In your React app, update the App.js
file with the following code:
That’s it! Now you have a React app that:
- Uses a tiny Node.js backend (
/auth/google
) to securely exchange OAuth codes for tokens. - Provides Okto with a valid Google ID token whenever
showOnboardingModal()
needs it.
Sample Implementation
For a complete working example, refer to the Okto React Template App or the Okto Next.js Starter App.
Common Tips & FAQ
-
Securing Secrets: Keep your Google Client Secret in environment variables, never commit it to git.
-
Local Development: For React, use
localhost:3000
for your front-end andlocalhost:3001
for your backend. For Next.js, you can do everything onlocalhost:3000
if using NextAuth. -
Custom Branding: Okto’s
brandData
allows you to pass title, subtitle, and icon to customize the onboarding modal. -
Primary Auth Method: By default, you can set
primaryAuth={AuthType.GAUTH}
(Google),AuthType.EMAIL
, orAuthType.PHONE
. You can also switch it dynamically if needed.