Authentication
Signup, login, passwordless, social, logout, password reset, and verification — all through `useNestAuth()`.
Every action on this page comes from the useNestAuth() hook. Each method is async (returns a Promise) and updates the provider's state — status, sessionData, isAuthenticated, error — on success or failure, so your screens re-render automatically.
Sign up
signup takes an email or phone plus a password:
Email & password login
Pass providerName: 'email' with credentials: { email, password }:
login also accepts createUserIfNotExists? and tenantId?. The full shape is login({ providerName?, credentials, createUserIfNotExists?, tenantId? }).
If the response has
isRequiresMfa === true, the account has two-factor enabled and login isn't finished yet — see MFA & tenancy.
Passwordless login
A two-step flow. First send a one-time code over email or sms:
Then complete login with the code the user received, using the passwordless provider:
Use channel: 'sms' (and channels: ['sms']) to deliver and verify the code by text instead.
Social login (native — no browser)
Google and Apple sign-in run through the platform's native flow, not a browser or webview. The SDK ships helper wrappers — signInWithGoogle and signInWithApple — that drive the native module and exchange the resulting token with your backend. You inject the native module, so this package carries no native dependency of its own.
Install and configure @react-native-google-signin/google-signin. Set webClientId to your web OAuth client ID so the returned ID token's audience matches the backend's google.clientId (or a google.audiences entry).
Apple
Use expo-apple-authentication (Expo) or @invertase/react-native-apple-authentication. signInWithApple presents the native sheet, forwards the identityToken, and passes the user's name (Apple returns it only on the first sign-in) plus an optional nonce for replay protection.
Backend config. Native Apple identityTokens are verified against Apple's JWKS — no client secret is needed for mobile. Set
apple.audiencesto include your iOS Bundle ID alongside the web Service ID (clientId). For Google, add any native client IDs togoogle.audiencesif your ID tokens aren't issued for the web client ID. The backend verifies the token, provisions the account on first sign-in, and links the identity atomically.
If you obtain a token another way, call the client directly:
Logout
logout ends the current session; logoutAll revokes every session for the user (all devices):
Both clear the stored tokens through your storage adapter, so the next launch starts unauthenticated.
Refresh & session checks
The client auto-refreshes near expiry, but you can also drive it manually:
isLoadingSessionData is true while getSessionData is in flight, if you want to show a spinner.
Password reset (forgot password)
Three steps: request a code, verify it to get a reset token, then set the new password.
For phone-based reset, pass phone instead of email to forgotPassword and verifyForgotPasswordOtp.
Change password (while signed in)
When the user is authenticated and knows their current password:
Email verification
Send a verification code, then confirm it:
Phone verification
Same shape, for the user's phone number:
Related
- MFA & tenancy — finish MFA-gated logins and switch tenants.
- Hooks & guards — read user/role/permission state and protect screens.