@knowcode/doc-builder 1.7.6 → 1.8.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.
Files changed (50) hide show
  1. package/.claude/settings.local.json +6 -1
  2. package/CHANGELOG.md +29 -0
  3. package/assets/css/notion-style.css +9 -1
  4. package/assets/js/main.js +10 -6
  5. package/html/README.html +44 -20
  6. package/html/auth.js +62 -13
  7. package/html/css/notion-style.css +9 -1
  8. package/html/documentation-index.html +44 -20
  9. package/html/guides/authentication-default-change.html +44 -20
  10. package/html/guides/authentication-guide.html +228 -263
  11. package/html/guides/claude-workflow-guide.html +44 -20
  12. package/html/guides/documentation-standards.html +44 -20
  13. package/html/guides/phosphor-icons-guide.html +44 -20
  14. package/html/guides/private-directory-authentication.html +472 -0
  15. package/html/guides/public-site-deployment.html +50 -25
  16. package/html/guides/search-engine-verification-guide.html +44 -20
  17. package/html/guides/seo-guide.html +44 -20
  18. package/html/guides/seo-optimization-guide.html +44 -20
  19. package/html/guides/troubleshooting-guide.html +44 -20
  20. package/html/guides/windows-setup-guide.html +44 -20
  21. package/html/index.html +44 -20
  22. package/html/js/auth.js +118 -39
  23. package/html/js/main.js +10 -6
  24. package/html/login.html +4 -4
  25. package/html/logout.html +2 -2
  26. package/html/private/cache-control-anti-pattern.html +408 -0
  27. package/html/private/launch/README.html +350 -0
  28. package/html/private/launch/auth-cleanup-summary.html +340 -0
  29. package/html/private/launch/bubble-plugin-specification.html +986 -0
  30. package/html/private/launch/go-to-market-strategy.html +716 -0
  31. package/html/private/launch/launch-announcements.html +646 -0
  32. package/html/private/launch/vercel-deployment-auth-setup.html +390 -0
  33. package/html/private/next-steps-walkthrough.html +685 -0
  34. package/html/private/supabase-auth-implementation-completed.html +433 -0
  35. package/html/private/supabase-auth-implementation-plan.html +590 -0
  36. package/html/private/supabase-auth-integration-plan.html +718 -0
  37. package/html/private/supabase-auth-setup-guide.html +545 -0
  38. package/html/private/test-private-doc.html +281 -0
  39. package/html/robots.txt +4 -0
  40. package/html/sitemap.xml +113 -29
  41. package/html/vercel-cli-setup-guide.html +44 -20
  42. package/html/vercel-first-time-setup-guide.html +44 -20
  43. package/lib/config.js +21 -3
  44. package/lib/core-builder.js +49 -7
  45. package/lib/supabase-auth.js +80 -25
  46. package/package.json +1 -1
  47. package/user-management/README.md +306 -0
  48. package/user-management/add-users.sh +730 -0
  49. package/user-management/create-user.js +65 -0
  50. package/user-management/users.txt +15 -0
@@ -3,19 +3,19 @@
3
3
  <head>
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta name="description" content="&gt; SECURITY WARNING: This basic authentication method has been deprecated and removed due to security vulnerabilities.">
7
- <title>⚠️ DEPRECATED: Basic Authentication Guide</title>
6
+ <meta name="description" content="@knowcode/doc-builder supports enterprise-grade authentication through Supabase - a secure, scalable authentication platform. This guide explains how to...">
7
+ <title>Authentication Guide for @knowcode/doc-builder</title>
8
8
 
9
9
  <meta name="author" content="Lindsay Smith">
10
- <meta name="keywords" content="documentation, markdown, static site generator, vercel, notion-style, authentication, login">
10
+ <meta name="keywords" content="documentation, markdown, static site generator, vercel, notion-style, supabase, authentication">
11
11
  <meta name="robots" content="index, follow">
12
12
  <link rel="canonical" href="https://doc-builder-delta.vercel.app/guides/authentication-guide.html">
13
13
 
14
14
  <!-- Open Graph / Facebook -->
15
15
  <meta property="og:type" content="article">
16
16
  <meta property="og:url" content="https://doc-builder-delta.vercel.app/guides/authentication-guide.html">
17
- <meta property="og:title" content="⚠️ DEPRECATED: Basic Authentication Guide">
18
- <meta property="og:description" content="&gt; SECURITY WARNING: This basic authentication method has been deprecated and removed due to security vulnerabilities.">
17
+ <meta property="og:title" content="Authentication Guide for @knowcode/doc-builder">
18
+ <meta property="og:description" content="@knowcode/doc-builder supports enterprise-grade authentication through Supabase - a secure, scalable authentication platform. This guide explains how to...">
19
19
  <meta property="og:image" content="https://doc-builder-delta.vercel.app/og-default.png">
20
20
  <meta property="og:site_name" content="@knowcode/doc-builder">
21
21
  <meta property="og:locale" content="en_US">
@@ -24,8 +24,8 @@
24
24
  <meta name="twitter:card" content="summary_large_image">
25
25
  <meta name="twitter:site" content="@planbbackups">
26
26
  <meta name="twitter:creator" content="@planbbackups">
27
- <meta name="twitter:title" content="⚠️ DEPRECATED: Basic Authentication Guide">
28
- <meta name="twitter:description" content="&gt; SECURITY WARNING: This basic authentication method has been deprecated and removed due to security vulnerabilities.">
27
+ <meta name="twitter:title" content="Authentication Guide for @knowcode/doc-builder">
28
+ <meta name="twitter:description" content="@knowcode/doc-builder supports enterprise-grade authentication through Supabase - a secure, scalable authentication platform. This guide explains how to...">
29
29
  <meta name="twitter:image" content="https://doc-builder-delta.vercel.app/og-default.png">
30
30
 
31
31
  <!-- Custom Meta Tags -->
@@ -46,6 +46,39 @@
46
46
  <link rel="stylesheet" href="/css/notion-style.css">
47
47
 
48
48
 
49
+ <!-- Hide content until auth check -->
50
+ <style>
51
+ body {
52
+ visibility: hidden;
53
+ opacity: 0;
54
+ transition: opacity 0.3s ease;
55
+ }
56
+ body.authenticated {
57
+ visibility: visible;
58
+ opacity: 1;
59
+ }
60
+ /* Show login/logout pages immediately */
61
+ body.auth-page {
62
+ visibility: visible;
63
+ opacity: 1;
64
+ }
65
+ /* Style auth button consistently */
66
+ .auth-btn {
67
+ background: none;
68
+ border: none;
69
+ color: var(--text-secondary);
70
+ cursor: pointer;
71
+ padding: 0.5rem;
72
+ border-radius: 0.5rem;
73
+ transition: all 0.2s;
74
+ font-size: 1.1rem;
75
+ }
76
+ .auth-btn:hover {
77
+ background: var(--bg-secondary);
78
+ color: var(--text-primary);
79
+ }
80
+ </style>
81
+
49
82
 
50
83
  <!-- Favicon -->
51
84
  <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>✨</text></svg>">
@@ -54,8 +87,8 @@
54
87
  {
55
88
  "@context": "https://schema.org",
56
89
  "@type": "TechArticle",
57
- "headline": "⚠️ DEPRECATED: Basic Authentication Guide",
58
- "description": "> SECURITY WARNING: This basic authentication method has been deprecated and removed due to security vulnerabilities.",
90
+ "headline": "Authentication Guide for @knowcode/doc-builder",
91
+ "description": "@knowcode/doc-builder supports enterprise-grade authentication through Supabase - a secure, scalable authentication platform. This guide explains how to...",
59
92
  "author": {
60
93
  "@type": "Person",
61
94
  "name": "Lindsay Smith"
@@ -65,8 +98,8 @@
65
98
  "name": "Knowcode Ltd",
66
99
  "url": "https://knowcode.tech"
67
100
  },
68
- "datePublished": "2025-07-25T13:49:06.520Z",
69
- "dateModified": "2025-07-25T13:49:06.520Z",
101
+ "datePublished": "2025-07-26T10:20:52.380Z",
102
+ "dateModified": "2025-07-26T10:20:52.380Z",
70
103
  "mainEntityOfPage": {
71
104
  "@type": "WebPage",
72
105
  "@id": "https://doc-builder-delta.vercel.app/guides/authentication-guide.html"
@@ -105,10 +138,14 @@
105
138
 
106
139
  <div class="header-actions">
107
140
  <div class="deployment-info">
108
- <span class="deployment-date" title="Built with doc-builder v1.7.5">Last updated: Jul 25, 2025, 01:49 PM UTC</span>
141
+ <span class="deployment-date" title="Built with doc-builder v1.8.0">Last updated: Jul 26, 2025, 10:20 AM UTC</span>
109
142
  </div>
110
143
 
111
144
 
145
+ <a href="../../login.html" class="auth-btn" title="Login/Logout">
146
+ <i class="fas fa-sign-in-alt"></i>
147
+ </a>
148
+
112
149
 
113
150
  <button id="theme-toggle" class="theme-toggle" aria-label="Toggle theme">
114
151
  <i class="fas fa-moon"></i>
@@ -164,31 +201,17 @@
164
201
  </a>
165
202
  <div class="nav-content" id="nav-guides-1">
166
203
  <a href="/guides/authentication-default-change.html" class="nav-item" data-tooltip="Starting from version 1.7.4, @knowcode/doc-builder now defaults to no authentication for all documentation sites."><i class="fas fa-file-alt"></i> Authentication Default Change</a>
167
- <a href="/guides/authentication-guide.html" class="nav-item active" data-tooltip="🚨 This authentication method has been REMOVED in version 2.0.0 due to serious security flaws."><i class="fas fa-file-alt"></i> Authentication Guide</a>
168
- <a href="/guides/cache-control-anti-pattern.html" class="nav-item" data-tooltip="Cache Control Anti-Pattern: Why Aggressive Cache-Busting is Bad for Documentation Sites."><i class="fas fa-file-alt"></i> Cache Control Anti Pattern</a>
204
+ <a href="/guides/authentication-guide.html" class="nav-item active" data-tooltip="@knowcode/doc-builder supports enterprise-grade authentication through Supabase - a secure, scalable authentication platform."><i class="fas fa-file-alt"></i> Authentication Guide</a>
169
205
  <a href="/guides/claude-workflow-guide.html" class="nav-item" data-tooltip="This guide demonstrates an efficient workflow for using Claude Code with a refined CLAUDE.md file to create high-quality documentation and deploy it..."><i class="fas fa-file-alt"></i> Claude Workflow Guide</a>
170
206
  <a href="/guides/documentation-standards.html" class="nav-item" data-tooltip="This document defines the documentation standards and conventions for the @knowcode/doc-builder project."><i class="fas fa-file-alt"></i> Documentation Standards</a>
171
- <a href="/guides/next-steps-walkthrough.html" class="nav-item" data-tooltip="Now that we&#039;ve implemented Supabase authentication, let&#039;s walk through testing the implementation and preparing for deployment."><i class="fas fa-file-alt"></i> Next Steps Walkthrough</a>
172
207
  <a href="/guides/phosphor-icons-guide.html" class="nav-item" data-tooltip="@knowcode/doc-builder automatically converts Unicode emojis in your markdown files to beautiful Phosphor icons in the generated HTML."><i class="fas fa-file-alt"></i> Phosphor Icons Guide</a>
208
+ <a href="/guides/private-directory-authentication.html" class="nav-item" data-tooltip="The @knowcode/doc-builder provides flexible authentication options to protect your documentation."><i class="fas fa-file-alt"></i> Private Directory Authentication</a>
173
209
  <a href="/guides/public-site-deployment.html" class="nav-item" data-tooltip="The @knowcode/doc-builder now supports deploying public documentation sites without authentication."><i class="fas fa-file-alt"></i> Public Site Deployment</a>
174
210
  <a href="/guides/search-engine-verification-guide.html" class="nav-item" data-tooltip="Search engine verification provides access to powerful webmaster tools:."><i class="fas fa-file-alt"></i> Search Engine Verification Guide</a>
175
211
  <a href="/guides/seo-guide.html" class="nav-item" data-tooltip="@knowcode/doc-builder includes comprehensive SEO (Search Engine Optimization) features to help your documentation rank better in search results and..."><i class="fas fa-file-alt"></i> Seo Guide</a>
176
212
  <a href="/guides/seo-optimization-guide.html" class="nav-item" data-tooltip="@knowcode/doc-builder includes comprehensive SEO (Search Engine Optimization) features that automatically optimize your documentation for search..."><i class="fas fa-file-alt"></i> Seo Optimization Guide</a>
177
- <a href="/guides/supabase-auth-implementation-plan.html" class="nav-item" data-tooltip="Supabase Auth Implementation Plan for @knowcode/doc-builder."><i class="fas fa-file-alt"></i> Supabase Auth Implementation Plan</a>
178
- <a href="/guides/supabase-auth-integration-plan.html" class="nav-item" data-tooltip="Supabase Authentication Integration Plan for @knowcode/doc-builder."><i class="fas fa-file-alt"></i> Supabase Auth Integration Plan</a>
179
- <a href="/guides/supabase-auth-setup-guide.html" class="nav-item" data-tooltip="@knowcode/doc-builder now supports enterprise-grade authentication through Supabase, replacing the previous insecure basic authentication."><i class="fas fa-file-alt"></i> Supabase Auth Setup Guide</a>
180
213
  <a href="/guides/troubleshooting-guide.html" class="nav-item" data-tooltip="This guide helps you resolve common issues when using @knowcode/doc-builder."><i class="fas fa-file-alt"></i> Troubleshooting Guide</a>
181
- <a href="/guides/vercel-deployment-auth-setup.html" class="nav-item" data-tooltip="Vercel Deployment Authentication Setup Guide."><i class="fas fa-file-alt"></i> Vercel Deployment Auth Setup</a>
182
214
  <a href="/guides/windows-setup-guide.html" class="nav-item" data-tooltip="This guide helps Windows users set up the complete AI-powered documentation workflow using Claude Code, @knowcode/doc-builder, and Vercel."><i class="fas fa-file-alt"></i> Windows Setup Guide</a></div></div>
183
- <div class="nav-section" data-level="1">
184
- <a class="nav-title collapsible" href="/launch/README.html" data-target="nav-launch-1" >
185
- <i class="fas fa-chevron-right collapse-icon"></i><i class="fas fa-folder"></i> Launch
186
- </a>
187
- <div class="nav-content collapsed" id="nav-launch-1">
188
- <a href="/launch/README.html" class="nav-item" data-tooltip="This directory contains all documentation related to the commercial launch of @knowcode/doc-builder, including go-to-market strategy, platform..."><i class="fas fa-file-alt"></i> Launch Overview</a>
189
- <a href="/launch/bubble-plugin-specification.html" class="nav-item" data-tooltip="This document outlines the technical specification for creating a Bubble.io plugin that integrates @knowcode/doc-builder, enabling Bubble developers..."><i class="fas fa-file-alt"></i> Bubble Plugin Specification</a>
190
- <a href="/launch/go-to-market-strategy.html" class="nav-item" data-tooltip="Go-to-Market Strategy &amp; Product Launch Plan."><i class="fas fa-file-alt"></i> Go To Market Strategy</a>
191
- <a href="/launch/launch-announcements.html" class="nav-item" data-tooltip="This document contains ready-to-use announcement templates for launching @knowcode/doc-builder across various platforms and channels."><i class="fas fa-file-alt"></i> Launch Announcements</a></div></div>
192
215
  </nav>
193
216
  <div class="resize-handle"></div>
194
217
  </aside>
@@ -196,281 +219,222 @@
196
219
  <!-- Content Area -->
197
220
  <main class="content">
198
221
  <div class="content-inner">
199
- <h1><i class="ph ph-warning-circle" aria-label="warning"></i> DEPRECATED: Basic Authentication Guide</h1>
200
- <blockquote>
201
- <p><strong>SECURITY WARNING</strong>: This basic authentication method has been deprecated and removed due to security vulnerabilities. </p>
202
- <p><strong>Use <a href="supabase-auth-setup-guide.md">Supabase Authentication</a> instead</strong> for secure, enterprise-grade authentication.</p>
203
- </blockquote>
204
- <h1>Authentication Guide for @knowcode/doc-builder (DEPRECATED)</h1>
222
+ <h1>Authentication Guide for @knowcode/doc-builder</h1>
205
223
  <h2>Overview</h2>
206
- <blockquote>
207
- <p><i class="ph ph-siren" aria-label="alert"></i> <strong>This authentication method has been REMOVED in version 2.0.0</strong> due to serious security flaws. Please migrate to <a href="supabase-auth-setup-guide.md">Supabase Authentication</a>.</p>
208
- </blockquote>
209
- <p>This guide explains the old, insecure authentication method that was available in @knowcode/doc-builder v1.x. It has been completely removed for security reasons.</p>
210
- <h2>What is Authentication?</h2>
211
- <p>The authentication feature in doc-builder provides a simple way to protect your documentation from unauthorized access. When enabled, users must log in with a username and password before viewing any documentation pages.</p>
212
- <h3>Features</h3>
213
- <ul>
214
- <li><i class="ph ph-check-circle" aria-label="checked"></i> <strong>Client-side authentication</strong> - Works with static site hosting</li>
215
- <li><i class="ph ph-check-circle" aria-label="checked"></i> <strong>Cookie-based sessions</strong> - Users stay logged in across pages</li>
216
- <li><i class="ph ph-check-circle" aria-label="checked"></i> <strong>Redirect handling</strong> - Returns users to requested page after login</li>
217
- <li><i class="ph ph-check-circle" aria-label="checked"></i> <strong>Logout functionality</strong> - Clear session and return to login</li>
218
- <li><i class="ph ph-check-circle" aria-label="checked"></i> <strong>Customizable credentials</strong> - Set your own username/password</li>
219
- </ul>
220
- <h3>Limitations</h3>
224
+ <p>@knowcode/doc-builder supports enterprise-grade authentication through <strong>Supabase</strong> - a secure, scalable authentication platform. This guide explains how to protect your documentation with proper user authentication and access control.</p>
225
+ <h2>Why Supabase?</h2>
221
226
  <ul>
222
- <li><i class="ph ph-warning-circle" aria-label="warning"></i> <strong>Basic security</strong> - Suitable for casual protection only</li>
223
- <li><i class="ph ph-warning-circle" aria-label="warning"></i> <strong>Client-side validation</strong> - Not suitable for highly sensitive data</li>
224
- <li><i class="ph ph-warning-circle" aria-label="warning"></i> <strong>Single user</strong> - No multi-user or role-based access</li>
225
- <li><i class="ph ph-warning-circle" aria-label="warning"></i> <strong>Credentials in JavaScript</strong> - Visible in browser developer tools</li>
227
+ <li><i class="ph ph-lock-key" aria-label="secure"></i> <strong>Enterprise Security</strong>: JWT tokens, bcrypt password hashing, Row Level Security</li>
228
+ <li><i class="ph ph-users" aria-label="team"></i> <strong>Multi-User Support</strong>: Unlimited users with fine-grained access control</li>
229
+ <li>🌍 <strong>Scalable</strong>: Built on PostgreSQL, handles millions of users</li>
230
+ <li><i class="ph ph-arrows-clockwise" aria-label="refresh"></i> <strong>Real-time</strong>: Live updates when permissions change</li>
231
+ <li><i class="ph ph-money" aria-label="money"></i> <strong>Generous Free Tier</strong>: 50,000 monthly active users free</li>
226
232
  </ul>
227
- <h2>How Authentication Works</h2>
233
+ <h2>How It Works</h2>
228
234
  <div class="mermaid-wrapper">
229
235
  <div class="mermaid">graph TD
230
- A[User visits page] --> B{Authenticated?}
236
+ A[User visits page] --> B{Has JWT Token?}
231
237
  B -->|No| C[Redirect to login]
232
- B -->|Yes| D[Show content]
238
+ B -->|Yes| D[Verify with Supabase]
233
239
  C --> E[Enter credentials]
234
- E --> F{Valid?}
235
- F -->|No| G[Show error]
236
- F -->|Yes| H[Set cookie]
237
- H --> I[Redirect to original page]
238
- G --> E
240
+ E --> F[Authenticate with Supabase]
241
+ F --> G{Valid?}
242
+ G -->|No| H[Show error]
243
+ G -->|Yes| I[Receive JWT token]
244
+ I --> J[Check site access]
245
+ J --> K{Has access?}
246
+ K -->|Yes| L[Show content]
247
+ K -->|No| M[Access denied]
248
+ D --> J
239
249
 
240
250
  style A fill:#e1f5fe
241
- style D fill:#c8e6c9
242
- style G fill:#ffcdd2</div>
251
+ style L fill:#c8e6c9
252
+ style M fill:#ffcdd2</div>
243
253
  </div>
244
- <h3>Technical Flow</h3>
254
+ <h2>Setting Up Authentication</h2>
255
+ <h3>Step 1: Create Supabase Project</h3>
245
256
  <ol>
246
- <li><strong>Page Load</strong>: Every page includes <code>auth.js</code> which checks for authentication</li>
247
- <li><strong>Cookie Check</strong>: Looks for <code>doc-auth</code> cookie with valid token</li>
248
- <li><strong>Redirect</strong>: Unauthenticated users sent to <code>/login.html</code></li>
249
- <li><strong>Login</strong>: Credentials validated client-side against config values</li>
250
- <li><strong>Session</strong>: Base64-encoded token stored in cookie</li>
251
- <li><strong>Access</strong>: Authenticated users can view all pages</li>
257
+ <li>Go to <a href="https://supabase.com">Supabase</a></li>
258
+ <li>Create a new project</li>
259
+ <li>Note your project URL and anon key</li>
252
260
  </ol>
253
- <h2>Configuration</h2>
254
- <h3>Enable Authentication</h3>
255
- <p>Authentication can be enabled in three ways:</p>
256
- <h4>1. Configuration File</h4>
257
- <p>Create <code>doc-builder.config.js</code> in your project root:</p>
261
+ <h3>Step 2: Configure doc-builder</h3>
262
+ <p>Create or update <code>doc-builder.config.js</code>:</p>
258
263
  <pre><code class="language-javascript">module.exports = {
259
- siteName: &#39;@knowcode/doc-builder&#39;,
260
- siteDescription: &#39;Internal documentation portal&#39;,
264
+ siteName: &#39;My Documentation&#39;,
261
265
 
262
266
  features: {
263
- authentication: true
267
+ authentication: &#39;supabase&#39; // Enable Supabase auth
264
268
  },
265
269
 
266
270
  auth: {
267
- username: &#39;myusername&#39;,
268
- password: &#39;mysecurepassword&#39;
271
+ supabaseUrl: &#39;https://your-project.supabase.co&#39;,
272
+ supabaseAnonKey: &#39;your-anon-key&#39;,
273
+ siteId: &#39;your-site-id&#39; // From database after setup
269
274
  }
270
275
  };
271
276
  </code></pre>
272
- <h4>2. Using Presets</h4>
273
- <p>Use the notion-inspired preset which has authentication enabled by default:</p>
274
- <pre><code class="language-bash">npx @knowcode/doc-builder@latest build --preset notion-inspired
277
+ <h3>Step 3: Set Up Database</h3>
278
+ <p>Run these SQL commands in your Supabase SQL editor:</p>
279
+ <pre><code class="language-sql">-- Create sites table
280
+ CREATE TABLE docbuilder_sites (
281
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
282
+ domain TEXT UNIQUE NOT NULL,
283
+ name TEXT NOT NULL,
284
+ created_at TIMESTAMPTZ DEFAULT NOW()
285
+ );
286
+
287
+ -- Create access table
288
+ CREATE TABLE docbuilder_access (
289
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
290
+ user_id UUID NOT NULL REFERENCES auth.users(id),
291
+ site_id UUID NOT NULL REFERENCES docbuilder_sites(id),
292
+ created_at TIMESTAMPTZ DEFAULT NOW(),
293
+ UNIQUE(user_id, site_id)
294
+ );
295
+
296
+ -- Enable Row Level Security
297
+ ALTER TABLE docbuilder_sites ENABLE ROW LEVEL SECURITY;
298
+ ALTER TABLE docbuilder_access ENABLE ROW LEVEL SECURITY;
299
+
300
+ -- Create policies
301
+ CREATE POLICY &quot;Sites visible to users with access&quot; ON docbuilder_sites
302
+ FOR SELECT USING (
303
+ id IN (
304
+ SELECT site_id FROM docbuilder_access
305
+ WHERE user_id = auth.uid()
306
+ )
307
+ );
308
+
309
+ CREATE POLICY &quot;Access visible to own user&quot; ON docbuilder_access
310
+ FOR SELECT USING (user_id = auth.uid());
275
311
  </code></pre>
276
- <p>Default credentials for preset:</p>
277
- <ul>
278
- <li>Username: <code>admin</code></li>
279
- <li>Password: <code>docs2025</code></li>
280
- </ul>
281
- <h4>3. Command Line</h4>
282
- <p>Disable authentication for a specific build:</p>
283
- <pre><code class="language-bash">npx @knowcode/doc-builder@latest build --no-auth
312
+ <h3>Step 4: Add Your Site</h3>
313
+ <pre><code class="language-sql">INSERT INTO docbuilder_sites (domain, name)
314
+ VALUES (&#39;your-domain.com&#39;, &#39;Your Documentation Name&#39;);
284
315
  </code></pre>
285
- <h3>Configuration Options</h3>
286
- <table>
287
- <thead>
288
- <tr>
289
- <th>Option</th>
290
- <th>Type</th>
291
- <th>Default</th>
292
- <th>Description</th>
293
- </tr>
294
- </thead>
295
- <tbody><tr>
296
- <td><code>features.authentication</code></td>
297
- <td>boolean</td>
298
- <td><code>false</code></td>
299
- <td>Enable/disable authentication</td>
300
- </tr>
301
- <tr>
302
- <td><code>auth.username</code></td>
303
- <td>string</td>
304
- <td><code>&#39;admin&#39;</code></td>
305
- <td>Login username</td>
306
- </tr>
307
- <tr>
308
- <td><code>auth.password</code></td>
309
- <td>string</td>
310
- <td><code>&#39;password&#39;</code></td>
311
- <td>Login password</td>
312
- </tr>
313
- </tbody></table>
314
- <h2>Usage</h2>
315
- <h3>For Site Administrators</h3>
316
- <ol>
317
- <li><strong>Set Credentials</strong>: Configure username/password in <code>doc-builder.config.js</code></li>
318
- <li><strong>Build Site</strong>: Run <code>npx @knowcode/doc-builder@latest build</code></li>
319
- <li><strong>Deploy</strong>: Upload to your hosting provider</li>
320
- <li><strong>Share Credentials</strong>: Provide login details to authorized users</li>
321
- </ol>
322
- <h3>For End Users</h3>
323
- <ol>
324
- <li><strong>Visit Site</strong>: Navigate to any documentation page</li>
325
- <li><strong>Login</strong>: Enter username and password on login page</li>
326
- <li><strong>Browse</strong>: Access all documentation pages</li>
327
- <li><strong>Logout</strong>: Click logout link in header (when available)</li>
328
- </ol>
329
- <h2>Security Considerations</h2>
330
- <h3><i class="ph ph-warning-circle" aria-label="warning"></i> Important Warnings</h3>
331
- <ol>
332
- <li><strong>Client-Side Only</strong>: Authentication happens in the browser, making it unsuitable for truly sensitive data</li>
333
- <li><strong>Visible Credentials</strong>: Username/password are embedded in JavaScript and visible to anyone who views page source</li>
334
- <li><strong>No Server Validation</strong>: Any user who knows the credentials can access the site</li>
335
- <li><strong>Static Files</strong>: All documentation files are still publicly accessible if URLs are known</li>
336
- </ol>
337
- <h3>When to Use</h3>
338
- <p><i class="ph ph-check-circle" aria-label="checked"></i> <strong>Good for:</strong></p>
339
- <ul>
340
- <li>Internal team documentation</li>
341
- <li>Preview deployments</li>
342
- <li>Casual access control</li>
343
- <li>Preventing search engine indexing</li>
344
- <li>Client presentations</li>
345
- </ul>
346
- <p><i class="ph ph-x-circle" aria-label="error"></i> <strong>Not suitable for:</strong></p>
316
+ <p>Note the returned ID - this is your <code>siteId</code> for the config.</p>
317
+ <h3>Step 5: Create Users</h3>
318
+ <p>Users can sign up through Supabase Auth, or you can create them:</p>
319
+ <pre><code class="language-sql">-- In Supabase dashboard, go to Authentication &gt; Users
320
+ -- Click &quot;Invite user&quot; and enter their email
321
+ </code></pre>
322
+ <h3>Step 6: Grant Access</h3>
323
+ <pre><code class="language-sql">-- Grant user access to your site
324
+ INSERT INTO docbuilder_access (user_id, site_id)
325
+ VALUES (
326
+ (SELECT id FROM auth.users WHERE email = &#39;user@example.com&#39;),
327
+ &#39;your-site-id&#39;
328
+ );
329
+ </code></pre>
330
+ <h2>Deployment</h2>
331
+ <h3>Build with Authentication</h3>
332
+ <pre><code class="language-bash"># Build with auth enabled (reads from config)
333
+ npx @knowcode/doc-builder build
334
+
335
+ # Build without auth (override config)
336
+ npx @knowcode/doc-builder build --no-auth
337
+ </code></pre>
338
+ <h3>Deploy to Vercel</h3>
339
+ <pre><code class="language-bash"># Deploy with auth
340
+ npx @knowcode/doc-builder deploy
341
+
342
+ # Deploy public site
343
+ npx @knowcode/doc-builder deploy --no-auth
344
+ </code></pre>
345
+ <h2>User Management</h2>
346
+ <h3>CLI Commands (Future)</h3>
347
+ <pre><code class="language-bash"># Add user to site
348
+ npx @knowcode/doc-builder auth:grant --email user@example.com --site-id xxx
349
+
350
+ # Remove user access
351
+ npx @knowcode/doc-builder auth:revoke --email user@example.com --site-id xxx
352
+
353
+ # List users with access
354
+ npx @knowcode/doc-builder auth:list-users --site-id xxx
355
+ </code></pre>
356
+ <h3>Manual Management</h3>
357
+ <p>Use Supabase dashboard or SQL commands to manage users and access.</p>
358
+ <h2>Security Features</h2>
359
+ <h3>What Supabase Provides</h3>
347
360
  <ul>
348
- <li>Highly confidential information</li>
349
- <li>Personal data (GDPR/privacy)</li>
350
- <li>Financial or legal documents</li>
351
- <li>Source code or API keys</li>
352
- <li>Medical records</li>
361
+ <li><i class="ph ph-check-circle" aria-label="checked"></i> <strong>JWT Authentication</strong>: Industry-standard secure tokens</li>
362
+ <li><i class="ph ph-check-circle" aria-label="checked"></i> <strong>Password Hashing</strong>: bcrypt with salt</li>
363
+ <li><i class="ph ph-check-circle" aria-label="checked"></i> <strong>Row Level Security</strong>: Database-level access control</li>
364
+ <li><i class="ph ph-check-circle" aria-label="checked"></i> <strong>Session Management</strong>: Automatic token refresh</li>
365
+ <li><i class="ph ph-check-circle" aria-label="checked"></i> <strong>Multi-Factor Auth</strong>: Optional 2FA support</li>
366
+ <li><i class="ph ph-check-circle" aria-label="checked"></i> <strong>OAuth Providers</strong>: Google, GitHub, etc. (optional)</li>
353
367
  </ul>
354
368
  <h3>Security Best Practices</h3>
355
369
  <ol>
356
- <li><strong>Use HTTPS</strong>: Always deploy to HTTPS-enabled hosting</li>
357
- <li><strong>Strong Passwords</strong>: Use complex, unique passwords</li>
358
- <li><strong>Regular Updates</strong>: Change credentials periodically</li>
359
- <li><strong>Monitor Access</strong>: Check hosting logs for unusual activity</li>
360
- <li><strong>Consider Alternatives</strong>: For sensitive data, use server-side authentication</li>
361
- </ol>
362
- <h2>Implementation Details</h2>
363
- <h3>Generated Files</h3>
364
- <p>When authentication is enabled, doc-builder creates:</p>
365
- <ol>
366
- <li><strong>login.html</strong> - Login page with form</li>
367
- <li><strong>logout.html</strong> - Logout confirmation page </li>
368
- <li><strong>auth.js</strong> - Authentication check script (included on all pages)</li>
370
+ <li><p><strong>Use environment variables</strong> for sensitive config:</p>
371
+ <pre><code class="language-javascript">auth: {
372
+ supabaseUrl: process.env.SUPABASE_URL,
373
+ supabaseAnonKey: process.env.SUPABASE_ANON_KEY,
374
+ siteId: process.env.DOC_SITE_ID
375
+ }
376
+ </code></pre>
377
+ </li>
378
+ <li><p><strong>Enable RLS policies</strong> on all tables</p>
379
+ </li>
380
+ <li><p><strong>Regular access audits</strong> - review who has access</p>
381
+ </li>
382
+ <li><p><strong>Use custom domains</strong> for professional appearance</p>
383
+ </li>
384
+ <li><p><strong>Monitor usage</strong> in Supabase dashboard</p>
385
+ </li>
369
386
  </ol>
370
- <h3>Cookie Format</h3>
371
- <p>The authentication cookie:</p>
372
- <ul>
373
- <li>Name: <code>doc-auth</code></li>
374
- <li>Value: Base64-encoded <code>username:password</code></li>
375
- <li>Path: <code>/</code> (entire site)</li>
376
- <li>Expiry: Session (until browser closed)</li>
377
- </ul>
378
- <h3>Customization</h3>
379
- <p>The login/logout pages use the same CSS as your documentation, inheriting your site&#39;s theme and styling.</p>
380
387
  <h2>Troubleshooting</h2>
381
388
  <h3>Common Issues</h3>
382
- <p><strong>Users get logged out frequently</strong></p>
383
- <ul>
384
- <li>Session cookies expire when browser closes</li>
385
- <li>Consider implementing &quot;remember me&quot; functionality</li>
386
- </ul>
387
- <p><strong>Login page shows but credentials don&#39;t work</strong></p>
388
- <ul>
389
- <li>Verify credentials in config match exactly (case-sensitive)</li>
390
- <li>Check browser console for JavaScript errors</li>
391
- <li>Ensure cookies are enabled</li>
392
- </ul>
393
- <p><strong>Some pages accessible without login</strong></p>
389
+ <p><strong>Users can&#39;t log in</strong></p>
394
390
  <ul>
395
- <li>Verify all HTML pages include auth.js</li>
396
- <li>Check for direct file access (PDFs, images)</li>
397
- <li>Ensure no pages exclude authentication script</li>
391
+ <li>Verify Supabase project is active</li>
392
+ <li>Check credentials are correct</li>
393
+ <li>Ensure user exists in auth.users</li>
394
+ <li>Verify site domain matches configuration</li>
398
395
  </ul>
399
- <p><strong>Login redirects to wrong page</strong></p>
396
+ <p><strong>Content flashes before redirect</strong></p>
400
397
  <ul>
401
- <li>Check redirect parameter handling</li>
402
- <li>Verify relative vs absolute URLs</li>
398
+ <li>This is fixed in latest versions</li>
399
+ <li>Ensure you&#39;re using @knowcode/doc-builder v1.7.4+</li>
403
400
  </ul>
404
- <h3>Debug Mode</h3>
405
- <p>Check browser developer console for:</p>
401
+ <p><strong>Access denied after login</strong></p>
406
402
  <ul>
407
- <li>Cookie values</li>
408
- <li>Redirect URLs </li>
409
- <li>JavaScript errors</li>
410
- <li>Network requests</li>
403
+ <li>Check user has entry in docbuilder_access table</li>
404
+ <li>Verify site_id matches your configuration</li>
405
+ <li>Check RLS policies are correctly set up</li>
411
406
  </ul>
412
- <h2>Alternatives</h2>
413
- <p>For more robust authentication, consider:</p>
407
+ <h3>Debug Checklist</h3>
414
408
  <ol>
415
- <li><strong>Vercel Authentication</strong> - Built-in password protection</li>
416
- <li><strong>Netlify Identity</strong> - User management service</li>
417
- <li><strong>Auth0</strong> - Full authentication platform</li>
418
- <li><strong>Cloudflare Access</strong> - Zero-trust security</li>
419
- <li><strong>Basic Auth</strong> - Server-level protection</li>
409
+ <li>Check browser console for errors</li>
410
+ <li>Verify JWT token in browser DevTools &gt; Application &gt; Storage</li>
411
+ <li>Test Supabase connection separately</li>
412
+ <li>Check network tab for API calls</li>
413
+ <li>Verify domain in database matches deployment</li>
420
414
  </ol>
421
- <h2>Example Implementation</h2>
422
- <h3>Simple Protected Docs</h3>
423
- <pre><code class="language-javascript">// doc-builder.config.js
424
- module.exports = {
425
- siteName: &#39;@knowcode/doc-builder&#39;,
426
- features: {
427
- authentication: true
428
- },
429
- auth: {
430
- username: &#39;team&#39;,
431
- password: &#39;handbook2025&#39;
432
- }
433
- };
434
- </code></pre>
435
- <h3>Build and Deploy</h3>
436
- <pre><code class="language-bash"># Build with authentication
437
- npx @knowcode/doc-builder@latest build
438
-
439
- # Deploy to Vercel
440
- npx @knowcode/doc-builder@latest deploy
415
+ <h2>Migration from Old Auth</h2>
416
+ <p>If you were using the old authentication system:</p>
417
+ <ol>
418
+ <li><p><strong>Remove old config</strong>:</p>
419
+ <pre><code class="language-javascript">// Remove this:
420
+ auth: {
421
+ username: &#39;admin&#39;,
422
+ password: &#39;password&#39;
423
+ }
441
424
  </code></pre>
442
- <h3>User Instructions</h3>
443
- <p>Email to team:</p>
444
- <pre><code>Our documentation is now available at:
445
- https://docs.example.com
446
-
447
- Login credentials:
448
- Username: team
449
- Password: handbook2025
450
-
451
- Please bookmark the site after logging in.
425
+ </li>
426
+ <li><p><strong>Set up Supabase</strong> following this guide</p>
427
+ </li>
428
+ <li><p><strong>Update config</strong> to use Supabase:</p>
429
+ <pre><code class="language-javascript">features: {
430
+ authentication: &#39;supabase&#39;
431
+ }
452
432
  </code></pre>
433
+ </li>
434
+ </ol>
453
435
  <h2>Conclusion</h2>
454
- <p>The authentication feature in @knowcode/doc-builder provides a simple way to add basic access control to your documentation. While not suitable for highly sensitive information, it&#39;s perfect for internal docs, client previews, and casual protection needs.</p>
455
- <p>Remember: For production use with sensitive data, always implement proper server-side authentication with your hosting provider.</p>
456
- <hr>
457
- <h2>Document History</h2>
458
- <table>
459
- <thead>
460
- <tr>
461
- <th>Date</th>
462
- <th>Version</th>
463
- <th>Author</th>
464
- <th>Changes</th>
465
- </tr>
466
- </thead>
467
- <tbody><tr>
468
- <td>2025-07-21</td>
469
- <td>1.0</td>
470
- <td>System</td>
471
- <td>Initial authentication guide</td>
472
- </tr>
473
- </tbody></table>
436
+ <p>Supabase authentication provides enterprise-grade security for your documentation while maintaining ease of use. With proper setup, you get secure, scalable authentication that grows with your needs.</p>
437
+ <p>For public documentation that doesn&#39;t need authentication, simply set <code>authentication: false</code> or use the <code>--no-auth</code> flag during build/deploy.</p>
474
438
 
475
439
  </div>
476
440
  </main>
@@ -487,6 +451,7 @@ Please bookmark the site after logging in.
487
451
  };
488
452
  </script>
489
453
  <script src="/js/main.js"></script>
490
-
454
+ <script src="https://unpkg.com/@supabase/supabase-js@2"></script>
455
+ <script src="/js/auth.js"></script>
491
456
  </body>
492
457
  </html>