FIX simpleauth for local dev

This commit is contained in:
Eddi3_As 2025-03-01 23:01:31 -05:00
parent 2499f78b6a
commit a049ba5da1
6 changed files with 11 additions and 25 deletions

View file

@ -1,6 +1,6 @@
# client
FROM node:20 AS build
FROM node:18 AS build
WORKDIR /usr/src/app/client

View file

@ -15,7 +15,7 @@ const OAuthCallback: React.FC = () => {
if (user) {
apiService.saveToken(user);
apiService.saveUsername(username || "");
navigate('/');
navigate('/teacher/dashboard');
} else {
navigate('/login');
}

View file

@ -50,13 +50,16 @@ class AuthManager{
}
// eslint-disable-next-line no-unused-vars
async login(userInfo,req,res,next){ //passport and simpleauth use next
async login(email,pswd,req,res,next){ //passport and simpleauth use next
const userInfo = await this.simpleregister.login(email, pswd);
const tokenToSave = jwt.create(userInfo.email, userInfo._id,userInfo.roles);
res.redirect(`/auth/callback?user=${tokenToSave}&username=${userInfo.name}`);
console.info(`L'utilisateur '${userInfo.name}' vient de se connecter`)
}
async register(userInfos){
console.log(userInfos);
if (!userInfos.email || !userInfos.password) {
throw new AppError(MISSING_REQUIRED_PARAMETER);
}

View file

@ -32,7 +32,7 @@ class SimpleAuth {
email: req.body.email,
password: req.body.password,
roles: req.body.roles
}
};
let user = await self.authmanager.register(userInfos)
if (user) res.redirect("/login")
}
@ -52,11 +52,8 @@ class SimpleAuth {
error.statusCode = 400;
throw error;
}
const userModel = self.authmanager.getUserModel();
const user = userModel.login(email, password);
await self.authmanager.login(user, req, res, next);
await self.authmanager.login(email, password, req, res, next);
} catch (error) {
const statusCode = error.statusCode || 500;
const message = error.message || "An internal server error occurred";

View file

@ -14,7 +14,7 @@
}
}
],
"simple-login": {
"simpleauth": {
"enabled": true,
"name": "provider3",
"SESSION_SECRET": "your_session_secret"

View file

@ -53,20 +53,6 @@ class Users {
return user;
}
async login(userid) {
await this.db.connect();
const conn = this.db.getConnection();
const userCollection = conn.collection("users");
const user = await userCollection.findOne({ _id: userid });
if (!user) {
return false;
}
return user;
}
/*
async login(email, password) {
try {
await this.db.connect();
@ -95,7 +81,7 @@ class Users {
throw error;
}
}
*/
async resetPassword(email) {
const newPassword = this.generatePassword();