Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ however if you initially set up via `npm adduser` and add your token u can still

## Features

- ✅ Only 2 config options: `endpoint`, `timeout`
- ✅ Only 1 required config option: `endpoint`
- ✅ Optional config options: `timeout`, `signupUrl`, `headers`
- ✅ Native `fetch()` (Node.js 18+)
- ✅ Timeout & Error Handling
- ✅ **JWT Support**: Web UI login works unchanged if you have added users via npm adduser
Expand Down Expand Up @@ -38,7 +39,9 @@ auth:
'@practical/verdaccio-api-token':
endpoint: https://your-api.com/verdaccio/verify # Required
timeout: 5000 # Optional (ms)
signupUrl: your signup page # Optional
signupUrl: your signup page # Optional
headers: # Optional
X-Custom-Header: some-value

# set your auth config as u like
packages:
Expand Down
5 changes: 4 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface ApiTokenAuthConfig {
endpoint: string;
signupUrl?: string;
timeout?: number;
headers?: Record<string, string>;
}

interface VerdaccioStuff {
Expand Down Expand Up @@ -57,6 +58,7 @@ export = function apiTokenAuth(
const endpoint = config.endpoint;
const signupUrl = config.signupUrl || 'your signup page';
const timeout = config.timeout ?? 5000;
const extraHeaders = config.headers ?? {};

// Cache validated tokens with their user data for performance
// Tokens are removed from cache when validation fails on subsequent requests
Expand Down Expand Up @@ -114,7 +116,8 @@ export = function apiTokenAuth(
'Content-Type': 'application/json',
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0'
'Expires': '0',
...extraHeaders
},
body: requestBody,
signal: controller.signal,
Expand Down