Repository: louislam/uptime-kuma
File: server/server.js (JavaScript)

Code before:
                        token: jwt.sign({
                            username: data.username,
                        }, jwtSecret),
                    })
                }

                if (user.twofaStatus == 1 && !data.token) {
                    callback({
                        tokenRequired: true,
                    })
                }

                if (data.token) {
                    let verify = notp.totp.verify(data.token, user.twofa_secret);

                    if (verify && verify.delta == 0) {
                        callback({
                            ok: true,
                            token: jwt.sign({
                                username: data.username,
                            }, jwtSecret),
                        })
                    } else {
                        callback({
                            ok: false,
                            msg: "Token Invalid!",
                        })
                    }
                }
            } else {
                callback({
                    ok: false,
                    msg: "Incorrect username or password.",
                })
            }

        });

        socket.on("logout", async (callback) => {
            socket.leave(socket.userID)
            socket.userID = null;
            callback();
        });

        socket.on("prepare2FA", async (callback) => {
            try {
                checkLogin(socket)

                let user = await R.findOne("user", " id = ? AND active = 1 ", [
                    socket.userID,
                ])

Review comment (suggestion):
```suggestion
                            msg: "Invalid Token!",
```

Code after:
                        token: jwt.sign({
                            username: data.username,
                        }, jwtSecret),
                    })
                }

                if (user.twofaStatus == 1 && !data.token) {
                    callback({
                        tokenRequired: true,
                    })
                }

                if (data.token) {
                    let verify = notp.totp.verify(data.token, user.twofa_secret);

                    if (verify && verify.delta == 0) {
                        callback({
                            ok: true,
                            token: jwt.sign({
                                username: data.username,
                            }, jwtSecret),
                        })
                    } else {
                        callback({
                            ok: false,
                            msg: "Invalid Token!",
                        })
                    }
                }
            } else {
                callback({
                    ok: false,
                    msg: "Incorrect username or password.",
                })
            }

        });

        socket.on("logout", async (callback) => {
            socket.leave(socket.userID)
            socket.userID = null;
            callback();
        });

        socket.on("prepare2FA", async (callback) => {
            try {
                checkLogin(socket)

                let user = await R.findOne("user", " id = ? AND active = 1 ", [
                    socket.userID,
                ])