Skip to main content

Refreshing Session Tokens

Session tokens can expire or become stale over time. If your application needs to maintain a user's session beyond the original token's validity period, you can use ductape.processor.sessions.refresh({...}) to generate a new token using a valid refresh token.

This allows you to keep the session alive without forcing the user to start a new session from scratch.

Overview

To refresh a session, you must pass the same session context along with the original refresh token returned by sessions.start({...}).

Input

The refresh({...}) method accepts the following object:

{
product: string;
env: string;
tag: string;
refreshToken: string; // refresh token
}
FieldTypeRequiredDescription
productstringYesThe tag of the product the session was associated with.
envstringYesThe environment slug (e.g., dev, snd, prd).
tagstringYesThe session tag used when the session was created.
refreshTokenstringYesThe refresh token returned by sessions.start({...}) or a previous refresh.

Output

The response will include a new session token and a new refresh token.

{
token: string; // New session token
refreshToken: string // New refresh token
}
FieldTypeDescription
tokenstringNew session token to use in subsequent calls
refreshTokenstringUse this to refresh again when needed

Example Usage

const refreshPayload = {
product: 'my-product',
env: 'dev',
tag: 'session-tag',
refreshToken: 'old-refresh-token-here'
};

const result = await ductape.processor.sessions.refresh(refreshPayload);

// result:
{
token: 'new-session-token',
refreshToken: 'new-refresh-token'
}

Use Cases

  • Maintain long-lived sessions without requiring re-authentication
  • Automatically refresh tokens in background jobs or frontend apps
  • Extend user journeys across multiple backend requests securely

See Also