Skip to main content

TokenManager

TokenManager is a thin wrapper around localStorage for persisting the Sentinel session token across page loads.

Responsibilities

ResponsibilityDetail
Read tokenReturns the current token from localStorage (or '' if absent)
Write tokenStores a new token issued by the server

Storage Key

The key is imported from @traveloka/app-meta as lsCmnSentinelToken, keeping it consistent with other platform-level storage conventions.

Public API

MethodSignatureDescription
getToken() => stringReturns stored token or empty string
setToken(token: string) => voidPersists token to localStorage

Token Lifecycle

  1. First visitgetToken() returns ''. The Sentinel.initialize() call sends an empty token to /sen/i.
  2. Server response — The server issues a new token in InitializeResponse.data.token. Sentinel calls setToken(token).
  3. Subsequent visits — The persisted token is read and sent with every initialisation and reporter flush.
  4. Token rotation — Both /sen/i and /sen/ss may return a new token. Sentinel always stores the latest value.

Dependencies

  • LocalStorage — Traveloka's safe localStorage wrapper from @traveloka/core.
  • @traveloka/app-meta — Provides the storage key constant.

SSR Safety

LocalStorage internally handles the typeof window === 'undefined' guard, so TokenManager is safe to instantiate during SSR (reads return '').


Last updated: 2026-02-24