---
title: "getCsrfToken"
source: "https://github.com/remix-run/remix/blob/8905f3943706e1f53696ab83e70a84873cabfc90/packages/csrf-middleware/src/lib/csrf.ts#L180"
---

# getCsrfToken

## Summary

Gets the CSRF token from the session. Creates one if missing.

## Signature

```ts
function getCsrfToken(context: AnyRequestContext, tokenKey: string): string

```

## Parameters

### `context`

Request context with a started session

### `tokenKey`

Session key that stores the token

## Returns

The active CSRF token