mirror of
https://github.com/GithubOrgProjectPiza/server.git
synced 2026-09-04 23:33:59 +02:00
Fix auth system
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user