feat: ShootTracker SQLite+JWT+YOLOv8

This commit is contained in:
ShootTracker Deploy
2026-04-30 22:44:27 +02:00
commit 2578cb6ec2
55 changed files with 5759 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import { Request, Response, NextFunction } from 'express'
import jwt from 'jsonwebtoken'
export interface AuthRequest extends Request {
userId?: string
userEmail?: string
}
const JWT_SECRET = process.env.JWT_SECRET || 'shoottracker-dev-secret-change-in-prod'
export function requireAuth(req: AuthRequest, res: Response, next: NextFunction) {
const authHeader = req.headers.authorization
if (!authHeader?.startsWith('Bearer ')) {
return res.status(401).json({ error: 'Token manquant' })
}
const token = authHeader.slice(7)
try {
const payload = jwt.verify(token, JWT_SECRET) as { userId: string; email: string }
req.userId = payload.userId
req.userEmail = payload.email
next()
} catch {
return res.status(401).json({ error: 'Token invalide ou expiré' })
}
}
export function signToken(userId: string, email: string): string {
return jwt.sign({ userId, email }, JWT_SECRET, { expiresIn: '30d' })
}