Merge pull request #369 from thelounge/xpaw/fix-losing-auth
Do not lose authentication token when the connection gets lost
This commit is contained in:
commit
75c578c02c
@ -74,28 +74,32 @@ $(function() {
|
||||
});
|
||||
});
|
||||
|
||||
socket.on("auth", function(/* data */) {
|
||||
socket.on("auth", function(data) {
|
||||
var body = $("body");
|
||||
var login = $("#sign-in");
|
||||
if (!login.length) {
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
login.find(".btn").prop("disabled", false);
|
||||
var token = window.localStorage.getItem("token");
|
||||
if (token) {
|
||||
|
||||
if (!data.success) {
|
||||
body.addClass("signed-out");
|
||||
|
||||
window.localStorage.removeItem("token");
|
||||
socket.emit("auth", {token: token});
|
||||
}
|
||||
if (body.hasClass("signed-out")) {
|
||||
|
||||
var error = login.find(".error");
|
||||
error.show().closest("form").one("submit", function() {
|
||||
error.hide();
|
||||
});
|
||||
} else {
|
||||
var token = window.localStorage.getItem("token");
|
||||
if (token) {
|
||||
socket.emit("auth", {token: token});
|
||||
}
|
||||
}
|
||||
if (!token) {
|
||||
body.addClass("signed-out");
|
||||
}
|
||||
|
||||
var input = login.find("input[name='user']");
|
||||
if (input.val() === "") {
|
||||
input.val(window.localStorage.getItem("user") || "");
|
||||
|
@ -106,7 +106,7 @@ function index(req, res, next) {
|
||||
|
||||
function init(socket, client) {
|
||||
if (!client) {
|
||||
socket.emit("auth");
|
||||
socket.emit("auth", {success: true});
|
||||
socket.on("auth", auth);
|
||||
} else {
|
||||
socket.on(
|
||||
@ -251,7 +251,7 @@ function auth(data) {
|
||||
}
|
||||
});
|
||||
if (!success) {
|
||||
socket.emit("auth");
|
||||
socket.emit("auth", {success: success});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user