0

So if i fail to login or user does not appear it will prompt a message failed to login or user not found and when that happens i wish the page to reload and go back to the login screen again, i tried with set timeout function but it does not seem to work. Thanks in advance

    if (error) {
        respond.json(error);
    } else {
        // If user can be found, result has one record
        if (result.length > 0) {
            if (input_password == result[0].user_password) {
                msg = "1"; // "Success!";
                console.log(msg);
            } else {
                msg = "Login Fail!";
                console.log(msg);
            }
        } else { // If user not found, result has no record
            setTimeout(function(){
            msg = "User not found!";

                window.location.reload(1);
             }, 2000);

        }
kloee
  • 21
  • 2
  • Something to consider: It is pretty well-established that authorisation should happen server-side, not in the browser. Something to read up on: client-side vs server-side auth. If you evaluate the risks and you're still fine with it, client side isn't wrong, just dangerous if you don't know the risks. If this is just a learning assignment, for example, nothing to worry about. – Sydney Y Feb 08 '20 at 06:30

1 Answers1

1

Try just using window.location.reload(true);

It sounds like you need a reference to this.

Why can't I pass "window.location.reload" as an argument to setTimeout?

So before you make the setTimeout save the reload function so it has the proper this.

var fun = window.location.reload(true);
setTimeout(function(){
            msg = "User not found!";

                fun();
             }, 2000);

So Bind it to

GrandFleet
  • 809
  • 2
  • 10
  • 25
  • cant seem to work still i just get stuck at the failed to log in message screen – kloee Feb 08 '20 at 05:47
  • So please review https://stackoverflow.com/questions/10839989/why-cant-i-pass-window-location-reload-as-an-argument-to-settimeout – GrandFleet Feb 08 '20 at 06:18