OAuth providers must be configured in the Sublay dashboard before use. Each
provider requires a client ID, client secret, and a list of allowed redirect
URIs.
Web Integration
TheuseOAuthSignIn hook (from @sublay/react-js) handles the full web OAuth flow.
Initiating Sign-In
CallinitiateOAuth with the provider name and the URL your app will redirect back to after authentication.
"google", "github", "apple", "facebook".
Handling the Callback
On the page your app redirects back to, callhandleOAuthCallback once on mount. It reads the tokens from the URL fragment, stores them in the SDK, and cleans the URL.
handleOAuthCallback returns true if tokens were found in the URL fragment and false otherwise. If the provider returned an error (for example, the user denied access), the error is surfaced through the error field.
Linking an Additional Provider
Authenticated users can link additional OAuth providers to their account usinglinkOAuthProvider. This requires the user to already be signed in.
handleOAuthCallback handles both cases.
Expo Integration
@sublay/expo ships its own useOAuthSignIn hook with the same API as the web hook (initiateOAuth, linkOAuthProvider, handleOAuthCallback, isLoading, error). Instead of a full-page redirect, it opens the Sublay-brokered consent screen in the system browser and returns to your app through a custom-scheme deep link.
Deep links don’t work reliably in Expo Go. You need a custom dev client (
npx expo run:ios / npx expo run:android) or an EAS Build.Setup
1
Install the peer dependencies
The Expo hook relies on
expo-web-browser (to open the auth session) and expo-linking (to parse the return URL).2
Register a URL scheme
Add a custom
scheme to your app.json (or app.config.js). This is the scheme your redirectAfterAuth deep link uses.app.json
3
Allow the redirect URI in the dashboard
In your Sublay project’s OAuth provider settings, add the exact deep link you’ll pass as
redirectAfterAuth (e.g. myapp://auth/callback) to the provider’s Allowed Redirect URIs.Initiating Sign-In
redirectAfterAuth is required on mobile — there is no window.location to fall back to. Pass the deep link you registered above.
handleOAuthCallback exists for API parity but is a no-op that always returns false, so you never need to call it on mobile.
If the user cancels or dismisses the browser, the flow resolves quietly: isLoading resets to false and error stays null. error is only set on a server failure, a provider error in the redirect, or when no tokens are returned.
Linking an Additional Provider
linkOAuthProvider works exactly like the web flow and requires the user to already be signed in.
Persistence
Tokens dispatched by the hook are picked up by theSublayProvider’s account manager and written to SecureStore, so the session survives app relaunches automatically. You don’t need to add any storage code.
Web vs. Expo at a glance
The Account Limit
A device stores at most 5 accounts (Multi-Account). Signing in a sixth through OAuth is refused — but on both platforms the limit surfaces as state, not as a thrown error, unlike email sign-up/sign-in and external auth, which reject the call. Read it fromuseAccounts (or useAddAccount) rather than from the hook’s error field, which stays reserved for failures the provider itself reported:
handleOAuthCallback is synchronous and shared by both platform packages. It returns as soon as it has read the redirect’s tokens — before your app knows whose they are — and on the web the page that called initiateOAuth was torn down by the redirect, so there is no promise left to reject. Making it reject would mean changing the shape of a function both packages depend on.
What happens instead. The identity is resolved, found to be new, and refused. The session that was just created is signed back out on the server, so nothing is orphaned, and the account that was active before is re-selected — but its session is not re-established, because the redirect had already replaced its tokens before the identity was known. The app renders signed-out with that account selected and the user picks it again from the switcher. Starting the flow from addAccount() changes nothing here — that call leaves the selection in place — so the account the user came from is the one restored. Only a device with no account selected at all stays on the sign-in screen.
An OAuth sign-in for an account the device already stores is never refused — the check is keyed on the resolved account id.
How Tokens Are Returned
After the provider callback, Sublay redirects to yourredirectAfterAuth URL with tokens in the URL fragment (not query parameters):
handleOAuthCallback extracts them automatically.
Managing Linked Identities
UseuseOAuthIdentities to list and unlink OAuth identities on the current user’s account.

