MDK Logo

Auth

Authentication helper functions

Helper functions for authentication flows.

Package

@tetherto/mdk-ui-foundation

Utilities

@tetherto/mdk-ui-foundation

Import the public APIs on this page from @tetherto/mdk-ui-foundation.

authTokenMutation

POST /auth/token — exchanges the current session for a fresh token. The refresh call gatewayRedirectAuth makes on its cadence.

Function

(client: QueryClient, fetcher: Fetcher = getFetcher(client) ?? mdkFetch) => { mutationKey: readonly ["auth", "token"]; mutationFn: (body?: AuthTokenRequest) => Promise<AuthTokenResponse>; }

bearerTokenAuth

Bearer-token session held in authStore: read the token per request, clear it when the backend reports the session ended.

Function

(options: BearerTokenAuthOptions = {}) => AuthProvider

extractAuthTokenFromUrl

Extract ?authToken= from a URL search string. Accepts either a full URL, a query string with leading ?, or a bare query string.

Function

(search: string) => string | null

gatewayRedirectAuth

Build the mining Gateway auth provider.

Function

(options: GatewayRedirectAuthOptions = {}) => AuthProvider

isSessionExpiredError

Default session-ended test: an MdkFetchError carrying 401.

Function

(error: unknown) => boolean

noAuth

No authentication: no token, no sign-in, nothing to expire.

Function

() => AuthProvider

SESSION_EXPIRED_STATUS

HTTP status a backend returns once the bearer token has expired. Any request — not just a token refresh — can surface it, which is why the guard lives on the QueryClient rather than in one hook.

Constant

401

stripAuthTokenFromUrl

Build a URL string with the ?authToken= parameter stripped. Used after the OAuth callback to remove the token from the address bar without losing any other query state.

Function

(search: string) => string

On this page