hardlounge/client/js/socket-events/auth.js

43 lines
813 B
JavaScript
Raw Normal View History

2017-05-18 20:08:54 +00:00
"use strict";
const $ = require("jquery");
const socket = require("../socket");
const storage = require("../localStorage");
socket.on("auth", function(data) {
const login = $("#sign-in");
let token;
const user = storage.get("user");
2017-05-18 20:08:54 +00:00
login.find(".btn").prop("disabled", false);
if (!data.success) {
storage.remove("token");
const error = login.find(".error");
error.show().closest("form").one("submit", function() {
error.hide();
});
} else if (user) {
2017-05-18 20:08:54 +00:00
token = storage.get("token");
if (token) {
$("#loading-page-message").text("Authorizing…");
socket.emit("auth", {user: user, token: token});
2017-05-18 20:08:54 +00:00
}
}
if (user) {
login.find("input[name='user']").val(user);
2017-05-18 20:08:54 +00:00
}
2017-05-18 20:08:54 +00:00
if (token) {
return;
}
2017-09-12 12:52:16 +00:00
$("#footer")
.find(".sign-in")
2017-05-18 20:08:54 +00:00
.trigger("click", {
pushState: false,
2017-09-12 12:52:16 +00:00
});
2017-05-18 20:08:54 +00:00
});