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