Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hzhu/node-provider-jwt

🔐 Node provider protection with JWTs in frontend dapps
https://github.com/hzhu/node-provider-jwt

alchemy dapp ethereum jwt quicknode-rpc

Last synced: 17 days ago
JSON representation

🔐 Node provider protection with JWTs in frontend dapps

Awesome Lists containing this project

README

        

# Node Provider Protection with JWTs in Frontend dApps

[![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white&style=flat-square)](https://medium.com/@henballs/protecting-node-provider-urls-for-frontend-dapps-c9a8159fc94d)
[![Medium](https://img.shields.io/badge/Vercel-000000?style=for-the-badge&logo=vercel&logoColor=white&style=flat-square)](https://node-provider-jwt-alpha.vercel.app)


Locks




This project demonstrates how to protect node provider API keys (e.g., for services like Alchemy) in frontend dApps using JWTs. By leveraging short-lived JWTs and refresh tokens, we can securely manage access to node providers without exposing API keys directly in the frontend. For a detailed explanation, check out the [blog post](https://medium.com/@henballs/protecting-node-provider-urls-for-frontend-dapps-c9a8159fc94d) here, and see the solution in action in the [demo app](https://node-provider-jwt-alpha.vercel.app).

## Features

- JWT Generation: Securely generate short-lived JWTs on the server.
- Token Refresh: Automatically refresh tokens before expiration to maintain user sessions.
- Middleware Integration: Handle refresh tokens using Next.js middleware.
- Edge Runtime Ready: Uses the jose package, which is optimized for edge runtimes.
- Secure HTTP-Only Cookies: Store refresh tokens securely using HTTP-only cookies to protect against JavaScript access and cross-site attacks.

## Getting Started

Follow these steps to set up the project locally:

### Prerequisites

- Node.js
- [bun](https://bun.sh)

### Environment Variables

Create a `.env` file in the root of the project and add the following environment variables. You can find the explanations for these variables in the [blog post](https://medium.com/@henballs/protecting-node-provider-urls-for-frontend-dapps-c9a8159fc94d).

```bash
ALCHEMY_PRIVATE_KEY_PKCS8=
ALCHEMY_KEY_ID=
REFRESH_TOKEN_SECRET=
NEXT_PUBLIC_WC_PROJECT_ID=
```

### Development Server

To run the application locally, run:

```bash
bun install
bun run dev
```