# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.plyr.network/api-reference/misc/verify-jwt-locally.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
