mirror of https://github.com/xfarrow/blink
update front-end
This commit is contained in:
parent
edcd53e761
commit
e62631b42f
|
@ -88,7 +88,7 @@ async function login (req, res) {
|
|||
const token = jwtUtils.generateToken(person.id);
|
||||
return res.status(200).json({ token });
|
||||
} else {
|
||||
return res.status(401).json({ error: 'Unauthorized' });
|
||||
return res.status(401).json({ error: 'Invalid credentials' });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error in function ${login.name}: ${error}`);
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
const apiUrl = 'http://localhost:3000/blinkapi';
|
|
@ -2,7 +2,7 @@
|
|||
<html lang="en" >
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>HTML5 Login Form with validation Example</title>
|
||||
<title>Log in - Blink</title>
|
||||
<link rel="stylesheet" href="../css/login-register.css">
|
||||
</head>
|
||||
<body>
|
||||
|
@ -28,6 +28,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../js/constants.js"></script>
|
||||
<script>
|
||||
async function login() {
|
||||
const email = document.getElementById("email").value;
|
||||
|
@ -37,7 +38,7 @@
|
|||
alert('Please fill in all fields');
|
||||
return;
|
||||
}
|
||||
const response = await fetch("http://localhost:3000/api/login", {
|
||||
const response = await fetch(`${API_URL}/login`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
email: email,
|
||||
|
@ -48,17 +49,14 @@
|
|||
});
|
||||
|
||||
const data = await response.json();
|
||||
if(response.status != 200){
|
||||
if(response.status == 401){
|
||||
alert('Login has failed');
|
||||
}
|
||||
else{
|
||||
alert('Internal server error');
|
||||
}
|
||||
|
||||
if(response.ok){
|
||||
console.log(`Login was successful. Token is ${data.token}`);
|
||||
document.cookie = `token=${data.token};`;
|
||||
window.location.href = 'userprofile.html?id=myself';
|
||||
}
|
||||
else{
|
||||
alert("Login was successful. Token will be stored in a cookie");
|
||||
document.cookie = `token=${data.token};`;
|
||||
alert(data.error);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
const API_URL = 'http://localhost:3000/api';
|
Loading…
Reference in New Issue