# Authentication

> Email OTP, OAuth deep links, and passkeys in React Native

> Authenticate users with `@abstraxn/signer-react-native`.

All examples assume your tree is wrapped in `AbstraxnProvider` (see [Installation](/guides/wallets/get-started/react-native/from-scratch/installation)).

## Email OTP

```tsx
import { useAbstraxnWallet } from "@abstraxn/signer-react-native";

const { loginWithOTP, verifyOTP, connect, getLastAuthState } = useAbstraxnWallet();

// 1) Send code
const { otpId } = await loginWithOTP("user@example.com");

// 2) Verify
await verifyOTP(otpId, "123456");

// 3) If MFA is required after verify, handle MFA first (see MFA guide)
const { mfaRequired } = getLastAuthState();
if (!mfaRequired) {
  await connect();
}
```

Or mount the optional sheet:

```tsx
import { OnboardingUI } from "@abstraxn/signer-react-native";

<OnboardingUI
  visible={showOnboarding}
  onClose={() => setShowOnboarding(false)}
  config={{ /* optional UI tweaks */ }}
/>
```

## Social OAuth (deep link)

RN cannot use a browser popup the same way as web. Flow:

1. Call `getGoogleAuthUrl` / `getDiscordAuthUrl` / `getTwitterAuthUrl` with your **redirect / universal link** origin.
2. Open the returned **`authUrl`** (`WebBrowser.openAuthSessionAsync`, `Linking.openURL`, etc.).
3. When the app resumes via deep link, call `completeOAuthReturnFromUrl(url, provider)`.

```tsx
import * as WebBrowser from "expo-web-browser";
import * as Linking from "expo-linking";
import { useAbstraxnWallet } from "@abstraxn/signer-react-native";

const { getGoogleAuthUrl, completeOAuthReturnFromUrl, connect, getLastAuthState } =
  useAbstraxnWallet();

async function startGoogleLogin() {
  const originUrl = Linking.createURL("/"); // your redirect base
  const { authUrl } = await getGoogleAuthUrl(originUrl);
  const result = await WebBrowser.openAuthSessionAsync(authUrl, originUrl);
  if (result.type === "success" && result.url) {
    await completeOAuthReturnFromUrl(result.url, "google");
    const { mfaRequired } = getLastAuthState();
    if (!mfaRequired) await connect();
  }
}
```

<Info>
Legacy backends that return OAuth `code` + `state` to the app can use `handleGoogleCallback(code, state)` (and Discord / Twitter equivalents) instead of `completeOAuthReturnFromUrl`.
</Info>

## Passkeys

Set `rpId` on the provider (and link the app to that domain):

- **iOS:** Associated Domains → `webcredentials:<rpId>` + valid `apple-app-site-association`
- **Android:** Digital Asset Links at `https://<rpId>/.well-known/assetlinks.json` (package + SHA-256)

```tsx
const { wallet, connect, getLastAuthState } = useAbstraxnWallet();

// Sign up (creates a passkey; user.id is base64url-safe for Android Credential Manager)
await wallet!.signupWithPasskey({ /* optional overrides */ });

// Login — discoverable by default (OS account picker).
// Pass overrides.credentialId only if you want to hint a specific credential.
await wallet!.loginWithPasskey();

const { mfaRequired } = getLastAuthState();
if (!mfaRequired) await connect();
```

### Behavior notes (core `0.1.2+` / `0.1.3+`)

- **Discoverable login:** last-used credential is **not** forced into `allowCredentials` unless you pass `overrides.credentialId`.
- **No account mix-up:** passkey login clears prior stored `USER` / `WHOAMI` before applying the login response profile.
- **Session key:** after login, the SDK may prompt for the **same passkey a second time** to register the device session key (`POST /auth/passkey/register-session`), unless the backend returns `sessionKeyRegistered: true`. This matches the web SDK and avoids later `PUBLIC_KEY_NOT_FOUND` signing errors.
- **No current Activity (Android, `0.1.3+`):** if the passkey prompt runs while no Activity is available, the SDK rejects with `NoActivity` / `"No current activity — please try again"` instead of crashing on `null`. Apps can drop `PasskeyModule.kt` / `patch-package` workarounds. `NO_ACTIVITY_PASSKEY_ERROR` is exported from core.

## Next

- [Hooks](/guides/wallets/get-started/react-native/from-scratch/hooks)
- [MFA](/guides/wallets/get-started/react-native/from-scratch/mfa)
- [Link auth methods](/guides/wallets/get-started/react-native/from-scratch/auth-linking)
