Checkpoint: Migration OAuth Manus vers authentification locale (80% complété) - Pages login/register créées, backend JWT implémenté, guides de déploiement ajoutés. Reste à corriger les doublons dans db.ts et finaliser AdminUsers.

This commit is contained in:
Manus Sandbox
2025-11-19 04:39:07 -05:00
parent 9d67724e83
commit 28727171ae
17 changed files with 2168 additions and 87 deletions

43
server/_core/auth.ts Normal file
View File

@@ -0,0 +1,43 @@
import bcrypt from "bcrypt";
import { sign, verify } from "jsonwebtoken";
import { ENV } from "./env";
const SALT_ROUNDS = 10;
/**
* Hashe un mot de passe avec bcrypt
*/
export async function hashPassword(password: string): Promise<string> {
return bcrypt.hash(password, SALT_ROUNDS);
}
/**
* Vérifie un mot de passe contre son hash
*/
export async function verifyPassword(
password: string,
hash: string
): Promise<boolean> {
return bcrypt.compare(password, hash);
}
/**
* Génère un token JWT pour un utilisateur
*/
export function generateToken(userId: number): string {
return sign({ userId }, ENV.jwtSecret, {
expiresIn: "30d",
});
}
/**
* Vérifie et décode un token JWT
*/
export function verifyToken(token: string): { userId: number } | null {
try {
const decoded = verify(token, ENV.jwtSecret) as { userId: number };
return decoded;
} catch {
return null;
}
}