rn
React Native (TypeScript) client SDK for the aice-auth issuer, with optional AsyncStorage-backed token persistence.
git@gitlab.com:aice-lab/auth/rn.git
Latest release
v1.0.0 ·
README
@aice-lab/auth-rn
React Native (TypeScript) client SDK for the
aice-auth issuer.
This package provides a thin, typed client for the /auth/login,
/auth/refresh, and /auth/logout endpoints, plus a pluggable token store
that defaults to @react-native-async-storage/async-storage for persistence
across app restarts.
Status
0.1.0 — MVP. First-factor login + refresh + logout. Step-up flows, social
providers, OIDC code exchange, and revocation broadcast are explicitly
out of scope for this version (see ARCHITECTURE.md).
Installation
npm install @aice-lab/auth-rn @react-native-async-storage/async-storage
react, react-native, and @react-native-async-storage/async-storage are
declared as peer dependencies so the host app controls the versions.
See DEPENDENCIES.md for supported ranges.
Quickstart
import { AiceAuthClient } from '@aice-lab/auth-rn';
const client = new AiceAuthClient({ issuerBaseUrl: 'https://id.example.com' });
const tokens = await client.login({
handleType: 'email',
handle: 'alice@example.org',
credential: 'correct-horse-battery-staple',
});
// Tokens persist in AsyncStorage automatically.
const accessToken = await client.getAccessToken();
// Rotate when the access token nears expiry.
await client.refresh();
// End the session and clear stored tokens.
await client.logout();
Custom token store
Inject any object that satisfies the TokenStore interface — e.g. an
encrypted-at-rest keychain wrapper:
import { AiceAuthClient, type TokenStore } from '@aice-lab/auth-rn';
const keychainStore: TokenStore = {
read: async () => /* ... */,
write: async (bundle) => /* ... */,
clear: async () => /* ... */,
};
const client = new AiceAuthClient({
issuerBaseUrl: 'https://id.example.com',
tokenStore: keychainStore,
});
Custom HTTP client
The client uses globalThis.fetch by default. Override for tests or to plug
in a request-tracing wrapper:
const client = new AiceAuthClient({
issuerBaseUrl: 'https://id.example.com',
httpClient: (input, init) => myInstrumentedFetch(input, init),
});
Public API
| Symbol | Kind | Notes |
|---|---|---|
AiceAuthClient | class | The main client. |
TokenBundle | interface | Mirrors the spec’s TokenBundle in camelCase. |
TokenStore | interface | read / write / clear async methods. |
MemoryTokenStore | class | In-memory store (tests). |
AsyncStorageTokenStore | class | Default; backed by AsyncStorage. |
HandleType | union type | 'phone' | 'email' | 'username'. |
AuthError | class | Typed error thrown by client methods. |
Anything not listed above is internal and may change between minor versions without notice.
Spec contract
This package is generated against the bundled OpenAPI document at
gitlab.com/aice-lab/auth/spec (/openapi/_bundled.yaml). The
TypeScript types are hand-written rather than codegen because the public
surface is small and the spec evolves slowly; conformance is enforced by
the upstream test-vector suite (planned for a later release).
License
FSL-1.1-Apache-2.0 — see LICENSE and LICENSE.FAQ.md.
This is a snapshot generated from GitLab. For the live README, see the project page.