# setToken

Learn how to replace any existing token with a new one.

This method sets a [JSON Web Token (JWT)](https://jwt.io) to identify the user.

This is equivalent to calling the [`identify`](identify), but instead of specifying the user ID, you provide the [token](/explanation/application/signed-tokens) directly.

Passing `null` as the token has the same effect as calling the [`unsetToken`](unset-token) method.

## Signature

This method has the following signature:

```ts
croct.setToken(token: string | null): void
```

## Example

Here is a basic example of how to use this method:

```ts
import croct from '@croct/plug';

croct.setToken('eyJhbGciOiJIUzI1Ni...');
```

## Parameters

The following list describes the supported parameters:

- `token`: `string | null`

  The base64-encoded [JSON Web Token (JWT)](https://jwt.io) to identify the user.

  Setting this parameter to `null` clears any previously specified token.
