feat(auth): génération automatique du JWT secret au démarrage
- secret.ts: génère un secret aléatoire 96 chars hex si absent - secret.ts: persiste dans data/secret.key (mode 600) - secret.ts: priorité env JWT_SECRET > secret.key > génération - auth: import JWT_SECRET depuis secret.ts au lieu de process.env - docker-compose: JWT_SECRET optionnel (géré automatiquement) - readme: mise à jour — JWT_SECRET n'est plus obligatoire - feat: add favicon.ico
This commit is contained in:
1 parent
867186db98
commit
e7afe138e1
3 files changed
+48
-4
No files matched your search
+3
-3
@@ -3,9 +3,9 @@ import path from 'path'
|
||||
import bcrypt from 'bcrypt'
|
||||
import jwt from 'jsonwebtoken'
|
||||
import type { Request, Response, NextFunction } from 'express'
|
||||
import { JWT_SECRET } from './secret.js'
|
||||
|
||||
const DATA_PATH = path.join(process.cwd(), 'data', 'auth.json')
|
||||
const JWT_SECRET = process.env.JWT_SECRET || 'fankarr-secret-change-me'
|
||||
const SALT_ROUNDS = 10
|
||||
|
||||
interface AuthData {
|
||||
@@ -63,7 +63,7 @@ export function authSetup(req: Request, res: Response): void {
|
||||
const passwordHash = bcrypt.hashSync(password, SALT_ROUNDS)
|
||||
writeAuth({ username, passwordHash })
|
||||
|
||||
const token = jwt.sign({ username }, JWT_SECRET, { expiresIn: '30d' })
|
||||
const token = jwt.sign({ username }, JWT_SECRET, { expiresIn: '1d' })
|
||||
res.cookie('fankarr_token', token, { httpOnly: true, sameSite: 'lax' })
|
||||
res.json({ success: true })
|
||||
}
|
||||
@@ -87,7 +87,7 @@ export function authLogin(req: Request, res: Response): void {
|
||||
return
|
||||
}
|
||||
|
||||
const token = jwt.sign({ username }, JWT_SECRET, { expiresIn: '30d' })
|
||||
const token = jwt.sign({ username }, JWT_SECRET, { expiresIn: '1d' })
|
||||
res.cookie('fankarr_token', token, { httpOnly: true, sameSite: 'lax' })
|
||||
res.json({ success: true })
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user