Skip to content

API Reference


API Reference / TokenManager

Class: TokenManager

Defined in: src/auth/TokenManager.ts:32

Keeps a valid access token available, renewing it before it expires.

Concurrent callers share one in-flight auth call. Without that, every request arriving while the token is stale would start its own login, and since generating a token can invalidate the previous one, a burst of traffic could leave the SDK holding a token the broker has already replaced.

Constructors

Constructor

new TokenManager(config, options): TokenManager

Defined in: src/auth/TokenManager.ts:37

Parameters

config

DhanClientConfig

options

EnableAutoTokenManagementOptions

Returns

TokenManager

Methods

ensureValidToken()

ensureValidToken(): Promise<string>

Defined in: src/auth/TokenManager.ts:52

Returns a usable token, generating or renewing only when needed.

Returns

Promise<string>


generate()

generate(): Promise<string>

Defined in: src/auth/TokenManager.ts:67

Forces a fresh login, ignoring any cached token.

Returns

Promise<string>


refresh()

refresh(): Promise<string>

Defined in: src/auth/TokenManager.ts:83

Extends the current token, falling back to a full login.

Renewal only works while the existing token is still valid, so an expired or rejected token has to go through the PIN/TOTP path again.

Returns

Promise<string>


getToken()

getToken(): TokenResponse | undefined

Defined in: src/auth/TokenManager.ts:106

The current token, if one has been obtained.

Returns

TokenResponse | undefined


clear()

clear(): void

Defined in: src/auth/TokenManager.ts:111

Drops the cached token so the next call logs in again.

Returns

void

Community project — not affiliated with Dhan. MIT License.