Display network/api errors on login/register page
This commit is contained in:
parent
c58c3fddd1
commit
b208088c0e
4
slowcord/login/package-lock.json
generated
4
slowcord/login/package-lock.json
generated
@ -40,7 +40,7 @@
|
|||||||
"picocolors": "^1.0.0",
|
"picocolors": "^1.0.0",
|
||||||
"proxy-agent": "^5.0.0",
|
"proxy-agent": "^5.0.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"typeorm": "^0.3.7",
|
"typeorm": "^0.2.37",
|
||||||
"typescript": "^4.4.2",
|
"typescript": "^4.4.2",
|
||||||
"typescript-json-schema": "^0.50.1"
|
"typescript-json-schema": "^0.50.1"
|
||||||
},
|
},
|
||||||
@ -9242,7 +9242,7 @@
|
|||||||
"proxy-agent": "^5.0.0",
|
"proxy-agent": "^5.0.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"ts-node": "^10.2.1",
|
"ts-node": "^10.2.1",
|
||||||
"typeorm": "^0.3.7",
|
"typeorm": "^0.2.37",
|
||||||
"typescript": "^4.4.2",
|
"typescript": "^4.4.2",
|
||||||
"typescript-json-schema": "^0.50.1"
|
"typescript-json-schema": "^0.50.1"
|
||||||
},
|
},
|
||||||
|
23
slowcord/login/public/js/handler.js
Normal file
23
slowcord/login/public/js/handler.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
const handleSubmit = async (path, body) => {
|
||||||
|
const failureMessage = document.getElementById("failure");
|
||||||
|
|
||||||
|
var response = await fetch(path, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
|
||||||
|
const json = await response.json();
|
||||||
|
if (json.token) {
|
||||||
|
window.localStorage.setItem("token", `"${json.token}"`);
|
||||||
|
window.location.href = "/app";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const error = json.errors ? Object.values(json.errors)[0]._errors[0].message : json.message;
|
||||||
|
|
||||||
|
failureMessage.innerHTML = error;
|
||||||
|
failureMessage.style.display = "block";
|
||||||
|
}
|
@ -11,6 +11,7 @@
|
|||||||
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
|
||||||
|
|
||||||
<link rel="stylesheet" href="./css/index.css">
|
<link rel="stylesheet" href="./css/index.css">
|
||||||
|
<script src="js/handler.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -67,25 +68,10 @@
|
|||||||
const email = data.get("email");
|
const email = data.get("email");
|
||||||
const password = data.get("password");
|
const password = data.get("password");
|
||||||
|
|
||||||
const response = await fetch("/api/v9/auth/login", {
|
await handleSubmit("/api/v9/auth/login", {
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
login: email,
|
login: email,
|
||||||
password: password,
|
password: password,
|
||||||
})
|
})
|
||||||
});
|
|
||||||
|
|
||||||
const json = await response.json();
|
|
||||||
if (json.token) {
|
|
||||||
window.localStorage.setItem("token", `"${json.token}"`);
|
|
||||||
window.location.href = "/app";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById("failure").style.display = "block";
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
|
||||||
|
|
||||||
<link rel="stylesheet" href="./css/index.css">
|
<link rel="stylesheet" href="./css/index.css">
|
||||||
|
<script src="js/handler.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -58,28 +59,13 @@
|
|||||||
const password = data.get("password");
|
const password = data.get("password");
|
||||||
const dob = data.get("dob");
|
const dob = data.get("dob");
|
||||||
|
|
||||||
const response = await fetch("/api/v9/auth/register", {
|
await handleSubmit("/api/v9/auth/register", {
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
consent: true,
|
consent: true,
|
||||||
email: email,
|
email: email,
|
||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
date_of_birth: dob,
|
date_of_birth: dob,
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const json = await response.json();
|
|
||||||
if (json.token) {
|
|
||||||
window.localStorage.setItem("token", `"${json.token}"`);
|
|
||||||
window.location.href = "/app";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById("failure").style.display = "block";
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user