---
url: >-
  https://game-engine-io.github.io/enginex-frontend-sdk/reference/api/@getenginex/sdk-next/server/functions/readCookieTokenStore.md
---
[Reference](../../../../index.md) / [@getenginex/sdk-next/server](../index.md) / readCookieTokenStore

# readCookieTokenStore()

> **readCookieTokenStore**(`options?`): `Promise`<[`TokenStore`](../../../sdk/interfaces/TokenStore.md)>

Reads on the server the session that the browser's `nextCookieTokenStore` writes to a cookie, for authenticated
calls with `getEnginexServer({ tokenStore })`.

* **Read-only:** returns a `memoryTokenStore` with the tokens of this request's cookie. Server
  Components do not write cookies, so `set`/`clear` (e.g. a login or logout done on the server) stay
  only in this store and never reach the browser. Writing the cookie from the server (Server Action, Route
  Handler) is out of scope: the session belongs to the browser.
* **No renewal:** the server client does not renew the session (`autoRefresh: false`). An expired access token
  makes calls fail with `UNAUTHENTICATED`; the browser renews it and rewrites the cookie.
* **Per request:** reads the current request's `cookies()`; nothing stays in module scope. Reading `cookies()`
  makes the route dynamic.
* **Next cache:** with `next: { revalidate }` in `getEnginexServer`, the user's responses enter
  Next's Data Cache (separated by token, but stored): do not combine `tokenStore` with `revalidate`
  for player data.

A missing or malformed cookie becomes "no session" (anonymous), without throwing.

## Parameters

### options?

[`ReadCookieTokenStoreOptions`](../interfaces/ReadCookieTokenStoreOptions.md) = `{}`

Cookie name.

## Returns

`Promise`<[`TokenStore`](../../../sdk/interfaces/TokenStore.md)>

Promise of a `TokenStore` with the cookie's session (or an empty one).

## Throws

The promise rejects outside a Next request (`cookies()` from `next/headers` throws).

## Example

```ts
// app/account/page.tsx (Server Component)
import { getEnginexServer, readCookieTokenStore } from '@getenginex/sdk-next/server'

export default async function Account() {
  const enginex = await getEnginexServer({ tokenStore: await readCookieTokenStore() })
  const balance = await enginex.wallet.getBalance()
  return <p>Balance: {balance.realBalance}</p>
}
```
