Skip to content

Function: getAccessToken() ​

ts
function getAccessToken(options?): Promise<IZaloAuthResponse>;

Returns a usable access token, refreshing it first when it expires within 60 seconds.

Zalo refresh tokens are single-use: the stored pair is replaced on refresh, and concurrent calls share one refresh request.

Parameters ​

ParameterTypeDescription
options?GetAccessTokenOptionsSee GetAccessTokenOptions.

Returns ​

Promise<IZaloAuthResponse>

Throws ​

NOT_AUTHENTICATED when there is no session, the numeric Zalo code when the refresh fails (call login() again), INVALID_RESPONSE when Zalo answers with an unexpected payload, or NOT_CONFIGURED when the Zalo App ID is missing.

Example ​

ts
const { accessToken } = await getAccessToken();
await fetch(`https://example.com/auth/zalo?token=${accessToken}`);

Released under the MIT License.