# @zyphr-dev/auth-react-native

React Native bindings for [Zyphr](https://zyphr.dev) auth. Same reactive session +
proactive token refresh as the web binding, plus a **secure-storage adapter** and
**refresh-on-foreground**.

- `<ZyphrAuthProvider>` — provides the session; refreshes when the app returns to the foreground.
- `useSession()` — reactive `{ status, accessToken, isAuthenticated }`.
- `useAuth()` — `login`, `logout`, `refresh`.

Built on [`@zyphr-dev/auth-core`](https://zyphr.dev/docs/sdks/auth) and the
client-safe `ZyphrClient` (publishable key).

## Install

```bash
npm i @zyphr-dev/auth-react-native @zyphr-dev/node-sdk
# plus your secure store (recommended):
npx expo install expo-secure-store
```

## Usage

```tsx
import * as SecureStore from 'expo-secure-store';
import { ZyphrClient } from '@zyphr-dev/node-sdk';
import {
  ZyphrAuthProvider,
  useSession,
  useAuth,
  secureStoreAdapter,
} from '@zyphr-dev/auth-react-native';

const client = new ZyphrClient({ applicationKey: 'za_pub_xxx' });

export default function App() {
  return (
    <ZyphrAuthProvider client={client} storage={secureStoreAdapter(SecureStore)}>
      <Screen />
    </ZyphrAuthProvider>
  );
}
```

```tsx
function Screen() {
  const { status, isAuthenticated } = useSession();
  const { login, logout } = useAuth();
  // render based on status / isAuthenticated
}
```

## Token storage

Pass a secure store — `secureStoreAdapter(SecureStore)` (encrypted; recommended)
or `asyncStorageAdapter(AsyncStorage)` (not encrypted; use only if you already
standardize on it). Both are optional peer dependencies — install whichever you
use. The default (no `storage`) is in-memory and does not survive an app restart,
so it's for prototyping only.

## Refresh on foreground

A backgrounded app's scheduled refresh timer may not fire reliably, so the
provider also refreshes when the app returns to `active` (via React Native's
`AppState`). Disable with `refreshOnForeground={false}`.
