mirror of
https://github.com/detleph/server.git
synced 2026-09-07 16:06:18 +02:00
Bugfix authentication controller
This commit is contained in:
@@ -36,7 +36,7 @@ interface AuthenticateUserBody {
|
|||||||
export const authenticateUser = async (req: Request<{}, {}, AuthenticateUserBody>, res: Response) => {
|
export const authenticateUser = async (req: Request<{}, {}, AuthenticateUserBody>, res: Response) => {
|
||||||
// TODO: Provide more useful error messages (Maybe express-validator?)
|
// TODO: Provide more useful error messages (Maybe express-validator?)
|
||||||
|
|
||||||
const { name, password } = req.body;
|
const { name, password } = req.body || {};
|
||||||
|
|
||||||
if (name == null || password == null) {
|
if (name == null || password == null) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
@@ -62,24 +62,22 @@ export const authenticateUser = async (req: Request<{}, {}, AuthenticateUserBody
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const param_password_hash = await argon2.hash(password, { type: argon2.argon2id });
|
if (await argon2.verify(user.password, password, { type: argon2.argon2id })) {
|
||||||
|
|
||||||
if (param_password_hash === user.password) {
|
|
||||||
// Set password revision ID in redis
|
// Set password revision ID in redis
|
||||||
await authClient.set(user.pid, user.revision);
|
await authClient.set(user.pid, user.revision);
|
||||||
|
|
||||||
return {
|
return res.status(200).json({
|
||||||
type: "success",
|
type: "success",
|
||||||
payload: {
|
payload: {
|
||||||
token: createAdminJWT(user),
|
token: createAdminJWT(user),
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return res.status(403).json({
|
||||||
type: "error",
|
type: "error",
|
||||||
payload: {
|
payload: {
|
||||||
message: "The provided credentials are not valid",
|
message: "The provided credentials are not valid",
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user