Skip to content

Overview

authfort-client is a TypeScript SDK for browsers and mobile apps. It handles the entire token lifecycle — login, refresh, 401 retry, and auth state management — so you don’t have to.

  • Token refresh — automatically refreshes before expiry
  • 401 retry — if a request gets 401, refreshes the token and retries once
  • Deduplication — multiple concurrent 401s share a single refresh call
  • Auth state — reactive state management with callbacks
  • Framework integrations — React, Vue, and Svelte hooks included
npm install authfort-client
npm install authfort-client
import { createAuthClient } from 'authfort-client';

const auth = createAuthClient({
  baseUrl: '/auth',
  tokenMode: 'cookie',
});

await auth.initialize();
await auth.signIn({ email: 'user@example.com', password: 'secret' });

// Authenticated requests — handles tokens automatically
const res = await auth.fetch('/api/profile');
const data = await res.json();
import { createAuthClient } from 'authfort-client';

const auth = createAuthClient({
  baseUrl: '/auth',
  tokenMode: 'cookie',
});

await auth.initialize();
await auth.signIn({ email: 'user@example.com', password: 'secret' });

// Authenticated requests — handles tokens automatically
const res = await auth.fetch('/api/profile');
const data = await res.json();
ModeHow Tokens Are SentStorageBest For
cookieHttpOnly cookies (automatic)Browser handles itWeb apps
bearerAuthorization: Bearer headerTokenStorage adapterMobile, desktop, non-browser

In cookie mode, auth.fetch() adds credentials: 'include' and the browser sends cookies automatically. In bearer mode, auth.fetch() reads the access token from memory and adds the Authorization header.