public/js/login.js
// loginUser does a post to our "api/login" route and if successful, redirects us the the members page
loginUser does a post to our "api/login" route and if successful, redirects us the the members page
loginUser does a post to our " api / login " route and if successful redirects us the the members page
function loginUser(username, password) {
    $.post("/api/login", {
      username: username,
      password: password
    }).then(function(data) {
      console.log(data);
      console.log(data.id)
      console.log("reached");
      $("#theForm").empty();
      $("#theForm").append(
        "<div class='d-flex justify-content-center'><h3 class='align-center'>" + data.username +"</h3></div>"+
        "<div class='d-flex flex-column mt-3'>"+
        "<div class='d-flex justify-content-center mb-0'><p>Current Score<p></div>"+
        "<div class='d-flex justify-content-center mt-0 mb-5'><h3>"+ data.score +"<h3></div>"
        +"</div>"
        );
      localStorage.setItem("user", data.username);
      localStorage.setItem("score", data.score);
      localStorage.setItem("id", data.id);
      console.log(localStorage.getItem("score"));
    }).catch(function(err) {
      console.log(err);
    });
  }
function loginUser ( username , password ) { $ . post ( "/api/login" , { username : username , password : password } ) . then ( function ( data ) { console . log ( data ) ; console . log ( data . id ) console . log ( "reached" ) ; $ ( "#theForm" ) . empty ( ) ; $ ( "#theForm" ) . append ( "<div class='d-flex justify-content-center'><h3 class='align-center'>" + data . username + "</h3></div>" + "<div class='d-flex flex-column mt-3'>" + "<div class='d-flex justify-content-center mb-0'><p>Current Score<p></div>" + "<div class='d-flex justify-content-center mt-0 mb-5'><h3>" + data . score + "<h3></div>" + "</div>" ) ; localStorage . setItem ( "user" , data . username ) ; localStorage . setItem ( "score" , data . score ) ; localStorage . setItem ( "id" , data . id ) ; console . log ( localStorage . getItem ( "score" ) ) ; } ) . catch ( function ( err ) { console . log ( err ) ; } ) ; }
loginUser does a post to our "api/login" route and if successful, redirects us the the members page
loginUser does a post to our " api / login " route and if successful redirects us the the members page
//window.location.replace(data); // If there's an error, log the error