fix: updated faliedLoginCount to failedLoginCount
This commit is contained in:
@@ -45,7 +45,7 @@ export async function authRoutes(fastify: FastifyInstance) {
|
|||||||
userInDB.passwordHash = hashedPassword;
|
userInDB.passwordHash = hashedPassword;
|
||||||
|
|
||||||
userInDB.blocked = false;
|
userInDB.blocked = false;
|
||||||
userInDB.faliedLoginCount = 0;
|
userInDB.failedLoginCount = 0;
|
||||||
await userInDB.save();
|
await userInDB.save();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -88,17 +88,15 @@ export async function authRoutes(fastify: FastifyInstance) {
|
|||||||
|
|
||||||
const match = await verify(userInDB.passwordHash, password);
|
const match = await verify(userInDB.passwordHash, password);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
if (!userInDB.faliedLoginCount) userInDB.faliedLoginCount = 0;
|
if (!userInDB.failedLoginCount) userInDB.failedLoginCount = 0;
|
||||||
if (userInDB.faliedLoginCount >= 4) userInDB.blocked = true;
|
if (userInDB.failedLoginCount >= 4) userInDB.blocked = true;
|
||||||
userInDB.faliedLoginCount++;
|
userInDB.failedLoginCount++;
|
||||||
await userInDB.save();
|
await userInDB.save();
|
||||||
|
|
||||||
return res
|
return res.code(401).send({
|
||||||
.code(401)
|
error: "invalid email or password",
|
||||||
.send({
|
failedLoginCount: userInDB.failedLoginCount,
|
||||||
error: "invalid email or password",
|
});
|
||||||
failedLoginCount: userInDB.faliedLoginCount,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const newSession = await createSession(
|
const newSession = await createSession(
|
||||||
@@ -108,7 +106,7 @@ export async function authRoutes(fastify: FastifyInstance) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
userInDB.lastLogin = new Date();
|
userInDB.lastLogin = new Date();
|
||||||
userInDB.faliedLoginCount = 0;
|
userInDB.failedLoginCount = 0;
|
||||||
await userInDB.save();
|
await userInDB.save();
|
||||||
|
|
||||||
res.send({ session_token: newSession.sid });
|
res.send({ session_token: newSession.sid });
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const userSchema = new mongoose.Schema({
|
|||||||
lastLogin: Date,
|
lastLogin: Date,
|
||||||
dev: Boolean,
|
dev: Boolean,
|
||||||
blocked: Boolean,
|
blocked: Boolean,
|
||||||
faliedLoginCount: {
|
failedLoginCount: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export async function createUser(
|
|||||||
status: input.password ? "active" : "invited",
|
status: input.password ? "active" : "invited",
|
||||||
passwordHash: hashedPassword,
|
passwordHash: hashedPassword,
|
||||||
blocked: false,
|
blocked: false,
|
||||||
faliedLoginCount: 0,
|
failedLoginCount: 0,
|
||||||
...input,
|
...input,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user