TokenManager
TokenManager is a thin wrapper around localStorage for persisting the Sentinel session token across page loads.
Responsibilities
| Responsibility | Detail |
|---|---|
| Read token | Returns the current token from localStorage (or '' if absent) |
| Write token | Stores 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
| Method | Signature | Description |
|---|---|---|
getToken | () => string | Returns stored token or empty string |
setToken | (token: string) => void | Persists token to localStorage |
Token Lifecycle
- First visit —
getToken()returns''. TheSentinel.initialize()call sends an empty token to/sen/i. - Server response — The server issues a new token in
InitializeResponse.data.token.SentinelcallssetToken(token). - Subsequent visits — The persisted token is read and sent with every initialisation and reporter flush.
- Token rotation — Both
/sen/iand/sen/ssmay return a new token.Sentinelalways stores the latest value.
Dependencies
LocalStorage— Traveloka's safelocalStoragewrapper 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