docusaurus-plugin-password-gate 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Royal Bissell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # docusaurus-plugin-password-gate
2
+
3
+ A client-side password gate for [Docusaurus](https://docusaurus.io/) v3 sites. Visitors must enter a password before seeing any content.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install docusaurus-plugin-password-gate
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ ### 1. Generate a password hash
14
+
15
+ ```bash
16
+ echo -n "your-password" | shasum -a 256 | cut -d " " -f 1
17
+ ```
18
+
19
+ Or use the bundled helper:
20
+
21
+ ```bash
22
+ ./node_modules/docusaurus-plugin-password-gate/scripts/hash-password.sh "your-password"
23
+ ```
24
+
25
+ ### 2. Add to `docusaurus.config.ts`
26
+
27
+ ```ts
28
+ export default {
29
+ plugins: [
30
+ [
31
+ 'docusaurus-plugin-password-gate',
32
+ {
33
+ passwordHash: '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',
34
+ },
35
+ ],
36
+ ],
37
+ };
38
+ ```
39
+
40
+ ## Options
41
+
42
+ | Option | Type | Default | Description |
43
+ | ---------------- | --------- | -------------------------------- | ------------------------------------------------ |
44
+ | `passwordHash` | `string` | **required** | SHA-256 hex hash of the password |
45
+ | `siteName` | `string` | `'Documentation'` | Heading shown on the gate screen |
46
+ | `placeholder` | `string` | `'Enter password'` | Input placeholder text |
47
+ | `buttonText` | `string` | `'Enter'` | Submit button label |
48
+ | `errorMessage` | `string` | `'Incorrect password.'` | Message shown after a failed attempt |
49
+ | `persistSession` | `boolean` | `false` | `true` = localStorage (survives restart), `false` = sessionStorage (clears on tab close) |
50
+ | `storageKey` | `string` | `'docusaurus-password-gate'` | Storage key used for the auth token |
51
+
52
+ ## Security Model
53
+
54
+ This plugin is **not a security boundary**. The password hash is shipped in the client-side JavaScript bundle and can be extracted by anyone who inspects it.
55
+
56
+ It is suitable for:
57
+
58
+ - Keeping casual visitors out of internal documentation
59
+ - Preventing search engine indexing of gated content
60
+ - Staging site access control where real auth is overkill
61
+
62
+ It is **not** suitable for:
63
+
64
+ - Protecting sensitive or regulated data
65
+ - Multi-user access control
66
+ - Compliance-regulated content
67
+
68
+ For truly sensitive content, pair this with hosting-level authentication (Cloudflare Access, nginx basic auth, Vercel password protection, etc.).
69
+
70
+ ## License
71
+
72
+ [MIT](LICENSE)
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '@docusaurus/types';
2
+ import type { PasswordGateOptions } from './options';
3
+ export default function pluginPasswordGate(_context: unknown, options: PasswordGateOptions): Plugin;
package/lib/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = pluginPasswordGate;
4
+ const SHA256_HEX_RE = /^[0-9a-f]{64}$/i;
5
+ function pluginPasswordGate(_context, options) {
6
+ if (!options.passwordHash || !SHA256_HEX_RE.test(options.passwordHash)) {
7
+ throw new Error('[docusaurus-plugin-password-gate] "passwordHash" must be a 64-character hex-encoded SHA-256 hash. ' +
8
+ 'Generate one with: echo -n "your-password" | shasum -a 256 | cut -d " " -f 1');
9
+ }
10
+ return {
11
+ name: 'docusaurus-plugin-password-gate',
12
+ getThemePath() {
13
+ return '../lib/theme';
14
+ },
15
+ contentLoaded({ actions }) {
16
+ actions.setGlobalData({
17
+ passwordHash: options.passwordHash,
18
+ siteName: options.siteName ?? 'Documentation',
19
+ placeholder: options.placeholder ?? 'Enter password',
20
+ buttonText: options.buttonText ?? 'Enter',
21
+ errorMessage: options.errorMessage ?? 'Incorrect password.',
22
+ persistSession: options.persistSession ?? false,
23
+ storageKey: options.storageKey ?? 'docusaurus-password-gate',
24
+ });
25
+ },
26
+ };
27
+ }
@@ -0,0 +1,9 @@
1
+ export interface PasswordGateOptions {
2
+ passwordHash: string;
3
+ siteName?: string;
4
+ placeholder?: string;
5
+ buttonText?: string;
6
+ errorMessage?: string;
7
+ persistSession?: boolean;
8
+ storageKey?: string;
9
+ }
package/lib/options.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { type ReactNode } from 'react';
2
+ export default function Root({ children }: {
3
+ children: ReactNode;
4
+ }): ReactNode;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = Root;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const useGlobalData_1 = require("@docusaurus/useGlobalData");
7
+ function isGateData(value) {
8
+ if (typeof value !== 'object' || value === null)
9
+ return false;
10
+ const obj = value;
11
+ return (typeof obj.passwordHash === 'string' &&
12
+ typeof obj.siteName === 'string' &&
13
+ typeof obj.placeholder === 'string' &&
14
+ typeof obj.buttonText === 'string' &&
15
+ typeof obj.errorMessage === 'string' &&
16
+ typeof obj.persistSession === 'boolean' &&
17
+ typeof obj.storageKey === 'string');
18
+ }
19
+ const BASE_DELAY_MS = 1000;
20
+ async function sha256(message) {
21
+ const msgBuffer = new TextEncoder().encode(message);
22
+ const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
23
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
24
+ return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
25
+ }
26
+ function getStorage(persist) {
27
+ if (typeof window === 'undefined')
28
+ return null;
29
+ return persist ? localStorage : sessionStorage;
30
+ }
31
+ function PasswordGate({ children, data }) {
32
+ const [authenticated, setAuthenticated] = (0, react_1.useState)(false);
33
+ const [ready, setReady] = (0, react_1.useState)(false);
34
+ const [error, setError] = (0, react_1.useState)(false);
35
+ const [input, setInput] = (0, react_1.useState)('');
36
+ const [locked, setLocked] = (0, react_1.useState)(false);
37
+ const failures = (0, react_1.useRef)(0);
38
+ (0, react_1.useEffect)(() => {
39
+ const storage = getStorage(data.persistSession);
40
+ if (storage?.getItem(data.storageKey) === 'authenticated') {
41
+ setAuthenticated(true);
42
+ }
43
+ setReady(true);
44
+ }, [data.persistSession, data.storageKey]);
45
+ const handleSubmit = (0, react_1.useCallback)(async (e) => {
46
+ e.preventDefault();
47
+ if (locked)
48
+ return;
49
+ const hash = await sha256(input);
50
+ if (hash === data.passwordHash) {
51
+ const storage = getStorage(data.persistSession);
52
+ storage?.setItem(data.storageKey, 'authenticated');
53
+ failures.current = 0;
54
+ setAuthenticated(true);
55
+ setError(false);
56
+ setInput('');
57
+ }
58
+ else {
59
+ failures.current += 1;
60
+ setError(true);
61
+ const delay = BASE_DELAY_MS * Math.pow(2, Math.min(failures.current - 1, 5));
62
+ setLocked(true);
63
+ setTimeout(() => setLocked(false), delay);
64
+ }
65
+ }, [input, data, locked]);
66
+ const handleInputChange = (0, react_1.useCallback)((e) => {
67
+ setInput(e.target.value);
68
+ if (error)
69
+ setError(false);
70
+ }, [error]);
71
+ if (authenticated) {
72
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
73
+ }
74
+ if (!ready) {
75
+ return null;
76
+ }
77
+ return ((0, jsx_runtime_1.jsx)("div", { style: styles.overlay, children: (0, jsx_runtime_1.jsxs)("form", { onSubmit: handleSubmit, style: styles.card, children: [(0, jsx_runtime_1.jsx)("h2", { style: styles.title, children: data.siteName }), (0, jsx_runtime_1.jsx)("label", { htmlFor: "password-gate-input", style: styles.srOnly, children: "Password" }), (0, jsx_runtime_1.jsx)("input", { id: "password-gate-input", type: "password", value: input, onChange: handleInputChange, placeholder: data.placeholder, "aria-describedby": error ? 'password-gate-error' : undefined, style: styles.input, autoFocus: true }), (0, jsx_runtime_1.jsx)("button", { type: "submit", disabled: locked, style: locked ? { ...styles.button, ...styles.buttonDisabled } : styles.button, children: locked ? 'Wait\u2026' : data.buttonText }), error && ((0, jsx_runtime_1.jsx)("p", { id: "password-gate-error", role: "alert", style: styles.error, children: data.errorMessage }))] }) }));
78
+ }
79
+ function Root({ children }) {
80
+ const raw = (0, useGlobalData_1.usePluginData)('docusaurus-plugin-password-gate');
81
+ if (!isGateData(raw)) {
82
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
83
+ }
84
+ return ((0, jsx_runtime_1.jsx)(PasswordGate, { data: raw, children: children }));
85
+ }
86
+ const styles = {
87
+ overlay: {
88
+ display: 'flex',
89
+ alignItems: 'center',
90
+ justifyContent: 'center',
91
+ minHeight: '100vh',
92
+ backgroundColor: '#1b1b1d',
93
+ fontFamily: 'system-ui, -apple-system, sans-serif',
94
+ },
95
+ card: {
96
+ display: 'flex',
97
+ flexDirection: 'column',
98
+ gap: '1rem',
99
+ padding: '2.5rem',
100
+ borderRadius: '8px',
101
+ backgroundColor: '#242526',
102
+ boxShadow: '0 4px 24px rgba(0,0,0,0.3)',
103
+ minWidth: '320px',
104
+ },
105
+ title: {
106
+ margin: 0,
107
+ color: '#e3e3e3',
108
+ fontSize: '1.25rem',
109
+ textAlign: 'center',
110
+ },
111
+ srOnly: {
112
+ position: 'absolute',
113
+ width: '1px',
114
+ height: '1px',
115
+ padding: 0,
116
+ margin: '-1px',
117
+ overflow: 'hidden',
118
+ clip: 'rect(0,0,0,0)',
119
+ whiteSpace: 'nowrap',
120
+ border: 0,
121
+ },
122
+ input: {
123
+ padding: '0.75rem 1rem',
124
+ borderRadius: '6px',
125
+ border: '1px solid #444',
126
+ backgroundColor: '#1b1b1d',
127
+ color: '#e3e3e3',
128
+ fontSize: '1rem',
129
+ outline: 'none',
130
+ },
131
+ button: {
132
+ padding: '0.75rem 1rem',
133
+ borderRadius: '6px',
134
+ border: 'none',
135
+ backgroundColor: '#3578e5',
136
+ color: '#fff',
137
+ fontSize: '1rem',
138
+ cursor: 'pointer',
139
+ fontWeight: 600,
140
+ },
141
+ buttonDisabled: {
142
+ opacity: 0.5,
143
+ cursor: 'not-allowed',
144
+ },
145
+ error: {
146
+ margin: 0,
147
+ color: '#fa383e',
148
+ fontSize: '0.875rem',
149
+ textAlign: 'center',
150
+ },
151
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "docusaurus-plugin-password-gate",
3
+ "version": "0.1.1",
4
+ "description": "Client-side password gate for Docusaurus sites",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "test": "vitest run",
13
+ "prepublishOnly": "npm run build"
14
+ },
15
+ "peerDependencies": {
16
+ "@docusaurus/core": "^3.0.0",
17
+ "react": "^18.0.0 || ^19.0.0",
18
+ "react-dom": "^18.0.0 || ^19.0.0"
19
+ },
20
+ "devDependencies": {
21
+ "@docusaurus/module-type-aliases": "^3.0.0",
22
+ "@docusaurus/types": "^3.0.0",
23
+ "typescript": "^5.0.0",
24
+ "vitest": "^4.1.2"
25
+ },
26
+ "keywords": [
27
+ "docusaurus",
28
+ "plugin",
29
+ "password",
30
+ "authentication",
31
+ "gate"
32
+ ],
33
+ "license": "MIT",
34
+ "author": "Royal Bissell",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/RoyalBis/docusaurus-plugin-password-gate.git"
38
+ },
39
+ "homepage": "https://github.com/RoyalBis/docusaurus-plugin-password-gate#readme",
40
+ "bugs": {
41
+ "url": "https://github.com/RoyalBis/docusaurus-plugin-password-gate/issues"
42
+ }
43
+ }