mirror of
https://github.com/xfarrow/blink
synced 2025-02-18 08:20:36 +01:00
Update login.html
This commit is contained in:
parent
6e3fd69bf8
commit
edcd53e761
@ -29,32 +29,38 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function login() {
|
async function login() {
|
||||||
const email = document.getElementById("email").value;
|
const email = document.getElementById("email").value;
|
||||||
const password = document.getElementById("password").value;
|
const password = document.getElementById("password").value;
|
||||||
|
|
||||||
if(!email || !password){
|
if(!email || !password){
|
||||||
return;
|
alert('Please fill in all fields');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
const response = await fetch("http://localhost:3000/api/login", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({
|
||||||
|
email: email,
|
||||||
|
password: password }),
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json; charset=UTF-8"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const options = {
|
const data = await response.json();
|
||||||
method: 'POST',
|
if(response.status != 200){
|
||||||
headers: {
|
if(response.status == 401){
|
||||||
'Content-Type': 'application/json'
|
alert('Login has failed');
|
||||||
},
|
}
|
||||||
body: JSON.stringify({ email, password }),
|
else{
|
||||||
};
|
alert('Internal server error');
|
||||||
|
}
|
||||||
fetch('http://localhost:3000/blinkapi/login', options)
|
|
||||||
.then(response => {})
|
|
||||||
.then(data => {
|
|
||||||
document.cookie = `token=${data.token};`;
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
alert("An error has occurred :-( please try again later")
|
|
||||||
console.error(err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
alert("Login was successful. Token will be stored in a cookie");
|
||||||
|
document.cookie = `token=${data.token};`;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user