@smart-auth/types
v0.1.2
Published
TypeScript interfaces, error classes, and type definitions for the Smart Auth SDK authentication ecosystem
Maintainers
Readme
@smart-auth/types
TypeScript type definitions for the Smart Auth SDK ecosystem.
What it does
@smart-auth/types provides all the TypeScript interfaces, error classes, and type definitions shared across the Smart Auth SDK packages. Install this if you need to type your own adapters, plugins, or custom integrations.
What's included
Interfaces
AuthConfig— Full configuration optionsAuthEngine<T>— The core auth engine interfaceAuthState<T>— Authentication state shapeTokenPair— Access + refresh token pairTokenPayload— Decoded JWT payloadStorageAdapter— Custom storage adapter interfaceLogger— Logger interface
Error Classes
AuthError— Base error class with status codes and JSON serializationTokenExpiredError— Thrown when a token has expiredRefreshFailedError— Thrown when token refresh failsUnauthorizedError— Thrown for 401/403 responsesSessionExpiredError— Thrown when the session has expired
Event Types
AuthEvent— Discriminated union of all auth eventsAuthEventType— Event type literals (login,logout,tokenRefreshed, etc.)
Installation
npm install @smart-auth/typesUsage
import type { AuthConfig, AuthEngine, StorageAdapter, TokenPair } from '@smart-auth/types';
import { AuthError, TokenExpiredError } from '@smart-auth/types';
// Type your custom storage
class MyCustomStorage implements StorageAdapter {
async get(key: string): Promise<string | null> {
/* ... */
}
async set(key: string, value: string): Promise<void> {
/* ... */
}
async remove(key: string): Promise<void> {
/* ... */
}
}
// Catch typed errors
try {
await auth.refreshToken();
} catch (error) {
if (error instanceof TokenExpiredError) {
// Handle expired token
}
}Part of Smart Auth SDK
This package is automatically installed as a dependency of other Smart Auth SDK packages. You only need to install it directly if you're building custom integrations.
License
MIT © Durjoy Ghosh
