feat: add permanent API keys for users

- Add api_key column to users table with auto-migration
- Modify auth middleware to accept both JWT (24h) and API keys (permanent)
- Add endpoints: GET/POST/DELETE /api/users/:id/api-key
- Update admin panel with API key management (generate, copy, regenerate, revoke)
- Update API documentation modal to show permanent API key usage

API keys use the format: nf_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Use header: X-API-Key: <your-key>
This commit is contained in:
Claude committed 2025-12-21 10:28:49 +00:00
1 parent 64ba174074
commit 239232c33c
5 files changed
+326 -28

No files matched your search

+11
View File
@@ -97,10 +97,21 @@ async function initDatabase() {
username VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
is_admin BOOLEAN DEFAULT FALSE,
api_key VARCHAR(64) UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
`);
// Migration: ajouter la colonne api_key si elle n'existe pas
await client.query(`
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'users' AND column_name = 'api_key') THEN
ALTER TABLE users ADD COLUMN api_key VARCHAR(64) UNIQUE;
END IF;
END $$;
`);
// Table notes
await client.query(`
CREATE TABLE IF NOT EXISTS notes (