mirror of
https://github.com/xfarrow/blink
synced 2025-02-27 09:37:36 +01:00
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);
|
const token = jwtUtils.generateToken(person.id);
|
||||||
return res.status(200).json({ token });
|
return res.status(200).json({ token });
|
||||||
} else {
|
} else {
|
||||||
return res.status(401).json({ error: 'Unauthorized' });
|
return res.status(401).json({ error: 'Invalid credentials' });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error in function ${login.name}: ${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" >
|
<html lang="en" >
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<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">
|
<link rel="stylesheet" href="../css/login-register.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -28,6 +28,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="../js/constants.js"></script>
|
||||||
<script>
|
<script>
|
||||||
async function login() {
|
async function login() {
|
||||||
const email = document.getElementById("email").value;
|
const email = document.getElementById("email").value;
|
||||||
@ -37,7 +38,7 @@
|
|||||||
alert('Please fill in all fields');
|
alert('Please fill in all fields');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await fetch("http://localhost:3000/api/login", {
|
const response = await fetch(`${API_URL}/login`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
email: email,
|
email: email,
|
||||||
@ -48,17 +49,14 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if(response.status != 200){
|
|
||||||
if(response.status == 401){
|
if(response.ok){
|
||||||
alert('Login has failed');
|
console.log(`Login was successful. Token is ${data.token}`);
|
||||||
}
|
|
||||||
else{
|
|
||||||
alert('Internal server error');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
alert("Login was successful. Token will be stored in a cookie");
|
|
||||||
document.cookie = `token=${data.token};`;
|
document.cookie = `token=${data.token};`;
|
||||||
|
window.location.href = 'userprofile.html?id=myself';
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
alert(data.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
1
frontend/vanilla/js/constants.js
Normal file
1
frontend/vanilla/js/constants.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
const API_URL = 'http://localhost:3000/api';
|
Loading…
x
Reference in New Issue
Block a user