mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-24 07:28:11 +02:00
Add user authentication and admin roles to manage application access
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
This commit is contained in:
1 parent
7b97fb4839
commit
5ee75edf8c
12 files changed
+1081
-61
No files matched your search
@@ -0,0 +1,45 @@
|
||||
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;
|
||||
Reference in new issue
Block a user