UNPKG

@nhost/nhost-js

Version:

Nhost JavaScript SDK

30 lines 1.36 kB
/** * Auth token refresh middleware for the Nhost SDK. * * This module provides middleware functionality to automatically refresh * authentication tokens before they expire, ensuring seamless API access * without requiring manual token refresh by the application. */ import type { Client } from '../auth'; import type { SessionStorage } from '../session/storage'; import type { ChainFunction } from './fetch'; /** * Creates a fetch middleware that automatically refreshes authentication tokens. * * This middleware: * 1. Checks if the current token is about to expire * 2. If so, uses the refresh token to obtain a new access token * * The middleware handles token refresh transparently, so the application * doesn't need to manually refresh tokens. * * @param auth - Auth API client for token refresh operations * @param storage - Storage implementation for persisting session data * @param options - Configuration options for token refresh behavior * @param options.marginSeconds - Number of seconds before token expiration to trigger a refresh, default is 60 seconds * @returns A middleware function that can be used in the fetch chain */ export declare const sessionRefreshMiddleware: (auth: Client, storage: SessionStorage, options?: { marginSeconds?: number; }) => ChainFunction; //# sourceMappingURL=middlewareSessionRefresh.d.ts.map