Skip to main content

refreshCookie

Proactively refreshes a cookie session using Roblox’s session refresh endpoint. This creates a new session and invalidates the old one, returning the new cookie. Use this to manually trigger cookie rotation before the automatic rotation kicks in, or to refresh cookies on a schedule to ensure they don’t expire. This function uses the library’s internal fetch mechanism, which includes:
  • Automatic CSRF token handling
  • Hardware-backed authentication (HBA) signatures
  • Generic challenge handling (if configured)
async function refreshCookie(cookieIndex?: number): Promise<RefreshCookieResult>

Parameters

Index in the cookie pool to refresh. Ignored if using a single cookie.

Returns

result
RefreshCookieResult
Result object with success status and new cookie value if successful.

Examples

import { refreshCookie } from 'rozod';

// Refresh the default/first cookie
const result = await refreshCookie();
if (result.success) {
  console.log('New cookie:', result.newCookie);
  // Persist the new cookie to your storage
  await db.updateCookie(result.poolIndex, result.newCookie);
} else {
  console.error('Refresh failed:', result.error);
}
Refreshing a cookie creates a new session and invalidates the old one. Make sure to persist the new cookie value immediately to avoid losing authentication.

getCookies

Gets the current cookie values from the pool. Useful for debugging or persisting all current cookie values.
function getCookies(): string[]

Returns

cookies
string[]
Array of current cookie values, or empty array if none configured.

Examples

import { getCookies } from 'rozod';

const allCookies = getCookies();
console.log(`Currently managing ${allCookies.length} cookies`);

updateCookie

Updates a specific cookie in the cookie pool by index. Useful for manually updating cookies when you receive rotation events through other means.
function updateCookie(index: number, newCookie: string): boolean

Parameters

index
number
required
The index in the cookie pool to update (0 for single cookie).
The new cookie value.

Returns

success
boolean
true if the cookie was updated, false if the index was invalid.

Examples

import { updateCookie } from 'rozod';

// Update the first (or only) cookie
const success = updateCookie(0, 'new_cookie_value');
if (success) {
  console.log('Cookie updated successfully');
}
The updateCookie function updates both the cookie pool and the session cookie cache (for 'none' rotation mode). The internal cookie pool is automatically updated when using refreshCookie or when RoZod detects automatic cookie rotation.

Types

RefreshCookieResult

type RefreshCookieResult = {
  success: boolean;
  /** The new cookie value if refresh was successful */
  newCookie?: string;
  /** Error message if refresh failed */
  error?: string;
  /** The index in the cookie pool that was refreshed */
  poolIndex: number;
}
Result of a manual cookie refresh operation.

Build docs developers (and LLMs) love