import { ReactNode, ReactElement } from 'react'; import { ZyphrClient } from '@zyphr-dev/node-sdk'; import { LoginParams, TokenStorage, SessionState, AuthTransport } from '@zyphr-dev/auth-core'; export { LoginParams, SessionState, SessionStatus, TokenStorage } from '@zyphr-dev/auth-core'; interface ZyphrAuthProviderProps { /** A client-safe ZyphrClient (constructed with your publishable application key). */ client: ZyphrClient; /** * Where tokens persist. Strongly recommended in production — pass a secure * store via `secureStoreAdapter(SecureStore)` (expo-secure-store) or * `asyncStorageAdapter(AsyncStorage)`. Defaults to in-memory (tokens are lost * on app restart), which is fine only for prototyping. */ storage?: TokenStorage; /** * Namespace the storage key so multiple providers can share one storage * adapter without colliding (e.g. one session per account for account * switching). The effective key becomes `${keyPrefix}zyphr.session`. Default `''`. */ keyPrefix?: string; /** Refresh this many ms before the access token expires. Default 60_000. */ refreshSkewMs?: number; /** * Refresh the session when the app returns to the foreground (default true). * A backgrounded app's scheduled refresh timer may not fire reliably, so we * also refresh on foreground to keep the token fresh. */ refreshOnForeground?: boolean; children: ReactNode; } /** * Provides a reactive Zyphr auth session to a React Native app. Same session * engine as the web binding (@zyphr-dev/auth-core), plus refresh-on-foreground * via React Native's AppState. Read state with {@link useSession}, act with * {@link useAuth}. */ declare function ZyphrAuthProvider({ client, storage, keyPrefix, refreshSkewMs, refreshOnForeground, children, }: ZyphrAuthProviderProps): ReactElement; /** Reactive session state — re-renders on login, logout, refresh. */ declare function useSession(): SessionState; interface UseAuthResult { login: (params: LoginParams) => Promise; logout: () => Promise; refresh: () => Promise; } /** Auth actions bound to the provider's session manager. */ declare function useAuth(): UseAuthResult; /** * An {@link AuthTransport} over the client-safe `ZyphrClient` (publishable * application key — no secret in the app bundle). Same transport the web binding * uses; re-implemented here so the React Native package doesn't depend on * `@zyphr-dev/auth-react` (which pulls web-React types). */ declare function createZyphrTransport(client: ZyphrClient, now?: () => number): AuthTransport; /** * The minimal async key/value shape common to React Native secure stores — * `expo-secure-store` (getItemAsync/setItemAsync/deleteItemAsync) and * `@react-native-async-storage/async-storage` (getItem/setItem/removeItem) both * fit one of these once wrapped. We keep the dependency OPTIONAL: the app passes * whichever it uses, so we don't force a native module on every consumer. */ /** Adapt `expo-secure-store` (the recommended secure default). */ declare function secureStoreAdapter(secureStore: { getItemAsync(key: string): Promise; setItemAsync(key: string, value: string): Promise; deleteItemAsync(key: string): Promise; }): TokenStorage; /** * Adapt `@react-native-async-storage/async-storage`. NOTE: AsyncStorage is NOT * encrypted — prefer {@link secureStoreAdapter} for tokens. Provided for apps * that already standardize on AsyncStorage and accept the tradeoff. */ declare function asyncStorageAdapter(asyncStorage: { getItem(key: string): Promise; setItem(key: string, value: string): Promise; removeItem(key: string): Promise; }): TokenStorage; /** The subset of `react-native-keychain` this adapter uses. */ interface KeychainModule { setGenericPassword(username: string, password: string, options?: { service?: string; }): Promise; getGenericPassword(options?: { service?: string; }): Promise; resetGenericPassword(options?: { service?: string; }): Promise; } /** * Adapt `react-native-keychain` (iOS Keychain / Android Keystore) — the * recommended secure store for **bare** React Native (no Expo). Encrypted at the * OS level, appropriate for long-lived refresh tokens. * * Keychain's API is service-based rather than key/value, so each storage `key` * maps to its own keychain **service** (`setGenericPassword(user, value, { service: key })`). * The core only ever uses a single key (`zyphr.session`, or `${keyPrefix}zyphr.session` * for per-account isolation), so each session is one service entry. * * ```ts * import * as Keychain from 'react-native-keychain'; * * ``` * * `react-native-keychain` is an OPTIONAL peer dependency — install it only if * you use this adapter. */ declare function keychainAdapter(keychain: KeychainModule): TokenStorage; export { type KeychainModule, type UseAuthResult, ZyphrAuthProvider, type ZyphrAuthProviderProps, asyncStorageAdapter, createZyphrTransport, keychainAdapter, secureStoreAdapter, useAuth, useSession };