mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
Following API best practices
This commit is contained in:
@ -43,7 +43,7 @@
|
||||
alert('Please fill in all fields');
|
||||
return;
|
||||
}
|
||||
const response = await fetch(`${API_URL}/login`, {
|
||||
const response = await fetch(`${API_URL}/persons/me/token`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
email: email,
|
||||
@ -59,7 +59,7 @@
|
||||
if (response.ok) {
|
||||
console.log(`Login was successful. Token is ${data.token}`);
|
||||
document.cookie = `token=${data.token};`;
|
||||
window.location.href = 'userprofile.html?id=myself';
|
||||
window.location.href = 'userprofile.html?id=me';
|
||||
} else {
|
||||
alert(data.error);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@
|
||||
}),
|
||||
};
|
||||
|
||||
fetch(`${API_URL}/register`, options)
|
||||
fetch(`${API_URL}/persons`, options)
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
alert("Congratulations! You've successfully registered to Blink." +
|
||||
|
@ -58,21 +58,21 @@
|
||||
let response;
|
||||
|
||||
// Retrieving the logged in user's profile
|
||||
if (!idToDisplay || idToDisplay === 'myself') {
|
||||
if (!idToDisplay || idToDisplay === 'me') {
|
||||
document.getElementById('editBadge').style.display = 'block'; // show edit button
|
||||
const token = getCookie('token');
|
||||
// Check whether the token exists
|
||||
if (!token) {
|
||||
window.location.href = 'login.html';
|
||||
}
|
||||
response = await fetch(`${API_URL}/person/myself`, {
|
||||
response = await fetch(`${API_URL}/persons/me`, {
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8",
|
||||
"authorization": token
|
||||
}
|
||||
});
|
||||
} else {
|
||||
response = await fetch(`${API_URL}/person/${idToDisplay}/details`, {
|
||||
response = await fetch(`${API_URL}/persons/${idToDisplay}/details`, {
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8",
|
||||
}
|
||||
|
Reference in New Issue
Block a user