handle null result from prompt(), fetch

This commit is contained in:
creeper123123321 2021-01-17 11:28:51 -03:00 committed by GitHub
parent 1222411fba
commit 5ecb2b49e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,8 @@ if (urlParams.get("mcauth_success") == "false") {
} }
function askWsUrl() { function askWsUrl() {
let url = prompt("VIAaaS instance websocket", localStorage.getItem("ws-url") || "wss://localhost:25543/ws"); let url = localStorage.getItem("ws-url") || "wss://localhost:25543/ws";
url = prompt("VIAaaS instance websocket", url) || url;
localStorage.setItem("ws-url", url); localStorage.setItem("ws-url", url);
return url; return url;
} }
@ -25,19 +26,18 @@ function getCorsProxy() {
function loginMc() { function loginMc() {
var clientToken = uuid.v4(); var clientToken = uuid.v4();
$.ajax({type: "post", fetch(getCorsProxy() + "https://authserver.mojang.com/authenticate", {method: "post",
url: getCorsProxy() + "https://authserver.mojang.com/authenticate", body: JSON.stringify({
data: JSON.stringify({
agent: {name: "Minecraft", version: 1}, agent: {name: "Minecraft", version: 1},
username: $("#email").val(), username: $("#email").val(),
password: $("#password").val(), password: $("#password").val(),
clientToken: clientToken, clientToken: clientToken,
}), }),
contentType: "application/json", headers: {"content-type": "application/json"}
dataType: "json" }).then((data) => {
}).done((data) => { if (data.status != 200) throw "not 200";
storeMcAccount(data.accessToken, data.clientToken, data.selectedProfile.name, data.selectedProfile.id); storeMcAccount(data.json().accessToken, data.json().clientToken, data.json().selectedProfile.name, data.json().selectedProfile.id);
}).fail(() => alert("Failed to login")); }).catch(() => alert("Failed to login"));
$("#email").val(""); $("#email").val("");
$("#password").val(""); $("#password").val("");
} }