Fix auth system

This commit is contained in:
Stefan-5422
2022-05-04 11:46:36 +02:00
parent 6099f58771
commit 7f52f8c30e
5 changed files with 14 additions and 11 deletions
+9 -3
View File
@@ -45,7 +45,9 @@ export const register = async (req: Request, res: Response) => {
);
}
const hash = await argon2.hash("salty" + password + "salty");
const hash = await argon2.hash("salty" + password + "salty",{
type: argon2.argon2id
});
if (!(await prisma.organization.findUnique({ where: { id: organization } }))) {
return res.status(404).json(createDefaultError(`Could not find organization with id ${organization}`, {}));
@@ -94,7 +96,9 @@ export const authenthicate = async (req: Request, res: Response) => {
);
}
const hash = await argon2.hash("salty" + password + "salty");
const hash = await argon2.hash("salty" + password + "salty",{
type: argon2.argon2id
});
const user = await prisma.user.findUnique({ where: { email: name } });
@@ -102,7 +106,7 @@ export const authenthicate = async (req: Request, res: Response) => {
return res.status(403).json(createDefaultError("Username or Password wrong", {}));
}
if (user.passwordHash !== hash) {
if (await argon2.verify(user.passwordHash,hash)) {
return res.status(403).json(createDefaultError("Username or Password wrong", {}));
}
@@ -112,6 +116,8 @@ export const authenthicate = async (req: Request, res: Response) => {
};
req.headers.authorization = jwt.sign(userjwt, JWT_SECRET);
res.status(200).json(createDefaultSucces("Logged in succesfully",{}))
};
export const verifyEmail = async (req: Request, res: Response) => {