fix: add README.md for @rep-protocol/next plugin; enhance keys management#42
Merged
olamide226 merged 1 commit intomainfrom Mar 19, 2026
Merged
fix: add README.md for @rep-protocol/next plugin; enhance keys management#42olamide226 merged 1 commit intomainfrom
olamide226 merged 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds documentation and improves dev-time key sharing for the @rep-protocol/next plugin so that REP payload encryption and /rep/session-key decryption remain consistent within a single Next.js dev server process.
Changes:
- Added a new
plugins/next/README.mdwith install/setup, security notes, and troubleshooting guidance. - Refactored
getOrCreateKeys()to use aglobalThis+Symbol.for(...)process-wide singleton to avoid key mismatches when modules are duplicated by bundlers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| plugins/next/src/keys.ts | Switches ephemeral key storage from module-scoped to process-wide singleton via globalThis + Symbol.for. |
| plugins/next/README.md | Introduces usage/setup docs and troubleshooting notes for the Next.js REP plugin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| ### 1. Add `<RepScript />` to your root layout | ||
|
|
||
| `RepScript` is a React Server Component that injects a `<script id="__rep__">` tag containing your REP variables. It only renders in development; in production (`NODE_ENV=production`) it returns `null`. |
|
|
||
| | Prop | Type | Default | Description | | ||
| | -------- | --------- | -------------- | ------------------------------------------------ | | ||
| | `env` | `string` | `".env.local"` | Path to env file, relative to project root. | |
|
|
||
| The handler returns the decryption key in development and a `404` in production (the gateway serves this endpoint in prod with rate limiting and single-use tokens). | ||
|
|
||
| **Static export (`output: "export"`):** Add `force-static` so the export build doesn't reject the route: |
|
|
||
| ## How it works | ||
|
|
||
| 1. **`RepScript`** reads `.env.local` at render time, classifies variables by prefix, encrypts sensitive vars with AES-256-GCM, and outputs a `<script type="application/json">` tag. |
| module.exports = nextConfig; | ||
| ``` | ||
|
|
||
| > With `output: "export"`, Next.js warns that rewrites don't apply to exported builds — this is expected. The rewrite only needs to work during `next dev`; in production the gateway serves `/rep/session-key` directly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a Next.js plugin for the Runtime Environment Protocol (REP) and improves the handling of ephemeral cryptographic keys to ensure singleton behavior across the development server. The main changes include adding comprehensive documentation for the plugin and refactoring the key management logic to use a process-wide singleton pattern.
Plugin Documentation and Usage
README.mdfor the@rep-protocol/nextplugin, including installation instructions, setup steps, security considerations, troubleshooting, and usage examples for integrating REP environment variables into Next.js projects.Key Management Improvements
getOrCreateKeysfunction inkeys.tsto useglobalThisand a unique symbol (Symbol.for('__rep_next_keys__')) for storing ephemeral cryptographic keys, ensuring singleton behavior even when modules are duplicated by bundlers in Next.js development.RepScriptand the session-key route handler now reliably share the same keys, matching the gateway's behavior and preventing key mismatches across module instances. in keys.ts