> For the complete documentation index, see [llms.txt](https://dev.plyr.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.plyr.network/api-reference/misc/verify-jwt-locally.md).

# Verify JWT Locally

{% hint style="info" %}
Verify a session JWT locally using the ES256 algorithm and a public key.
{% endhint %}

## Verification Process

To verify a JWT locally, you'll need:

1. The JWT token to verify
2. The public key in PEM format (base64 encoded)

### Parameters

```typescript
{
  token: string,      // The JWT to verify
  publicKey: string   // Base64 encoded public key (must be decoded to UTF-8 before use)
}
```

### Example Usage

```typescript
try {
    const decodedToken = jwt.verify(token, Buffer.from(base64PublicKey, 'base64').toString('utf-8'), { algorithms: ['ES256'] });
    // JWT is valid, decodedToken contains the payload
} catch (error) {
    // JWT verification failed
    console.error(error.message);
}
```

### Error Cases

Verification will throw an error if:

* The JWT format is invalid
* The signature is invalid
* The token has expired (due to logout for example)
* The algorithm doesn't match (must be ES256)
