mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-12 01:36:54 +02:00
Implement user login, session management, and role-based access control for users and administrators. Includes new admin pages for user management and SQL query execution. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/HPCBgsr
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import passport from "passport";
|
|
import { Strategy as LocalStrategy } from "passport-local";
|
|
import bcrypt from "bcrypt";
|
|
import { storage } from "./storage";
|
|
import type { User } from "@shared/schema";
|
|
|
|
// Configuration de la stratégie locale
|
|
passport.use(
|
|
new LocalStrategy(async (username, password, done) => {
|
|
try {
|
|
const user = await storage.getUserByUsername(username);
|
|
|
|
if (!user) {
|
|
return done(null, false, { message: "Nom d'utilisateur ou mot de passe incorrect" });
|
|
}
|
|
|
|
const isValidPassword = await bcrypt.compare(password, user.password);
|
|
|
|
if (!isValidPassword) {
|
|
return done(null, false, { message: "Nom d'utilisateur ou mot de passe incorrect" });
|
|
}
|
|
|
|
return done(null, user);
|
|
} catch (error) {
|
|
return done(error);
|
|
}
|
|
})
|
|
);
|
|
|
|
// Sérialisation de l'utilisateur pour la session
|
|
passport.serializeUser((user: Express.User, done) => {
|
|
done(null, (user as User).id);
|
|
});
|
|
|
|
// Désérialisation de l'utilisateur depuis la session
|
|
passport.deserializeUser(async (id: string, done) => {
|
|
try {
|
|
const user = await storage.getUser(id);
|
|
done(null, user);
|
|
} catch (error) {
|
|
done(error);
|
|
}
|
|
});
|
|
|
|
export default passport;
|