mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-15 03:07:29 +02:00
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:
5 files changed
+326
-28
No files matched your search
@@ -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 (
|
||||
|
||||
Reference in new issue
Block a user