mirror of
https://gitlab.com/little-lines/frontend.git
synced 2024-11-22 06:36:52 +00:00
Check login status and disable button on setting
This commit is contained in:
parent
240701ed7a
commit
82e1e4e86a
3 changed files with 49 additions and 30 deletions
|
@ -259,35 +259,44 @@ export default {
|
||||||
this.showRoute = false;
|
this.showRoute = false;
|
||||||
},
|
},
|
||||||
addToFavorites() {
|
addToFavorites() {
|
||||||
console.log('on click');
|
const currentUser = JSON.parse(sessionStorage.getItem('current_user'));
|
||||||
fetch("https://little-lines-backend.techtransthai.org/api/favorites/create",{
|
|
||||||
method: "POST",
|
if (currentUser) {
|
||||||
headers: {
|
console.log('Logged in. Proceed to add to favorites.');
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
fetch("https://little-lines-backend.techtransthai.org/api/favorites/create", {
|
||||||
body: JSON.stringify({
|
method: "POST",
|
||||||
user_id: '123456789',
|
headers: {
|
||||||
place_name: this.nearestStructureData.display_name,
|
'Content-Type': 'application/json',
|
||||||
location: {
|
},
|
||||||
type: "Point",
|
body: JSON.stringify({
|
||||||
coordinates: [parseFloat(this.nearestStructureData.lon), parseFloat(this.nearestStructureData.lat)]
|
user_id: currentUser.id, // ใช้ userId ของผู้ใช้ที่ล็อกอินอยู่
|
||||||
},
|
place_name: this.nearestStructureData.display_name,
|
||||||
wheelchair_access: 'Accessible',
|
location: {
|
||||||
highway_type: 'Highway'
|
type: "Point",
|
||||||
})
|
coordinates: [parseFloat(this.nearestStructureData.lon), parseFloat(this.nearestStructureData.lat)]
|
||||||
|
},
|
||||||
|
wheelchair_access: 'Accessible',
|
||||||
|
highway_type: 'Highway'
|
||||||
})
|
})
|
||||||
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
console.log('Add to favorites success');
|
console.log('Add to favorites success');
|
||||||
return res.json();
|
return res.json();
|
||||||
} else {
|
} else {
|
||||||
throw Error(`Add to favorited faild (${res.status})`);
|
throw Error(`Add to favorites failed (${res.status})`);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
|
console.log('User not logged in. Unable to add to favorites.');
|
||||||
|
this.$router.push({ name: 'login' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -116,10 +116,10 @@ export default {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
// localStorage.setItem('isLoggedIn', true);
|
|
||||||
// console.log(isLoggedIn);
|
|
||||||
console.log(data.success);
|
console.log(data.success);
|
||||||
sessionStorage.setItem('current_user', JSON.stringify({id:data.user._id,username:data.user.username,email:data.user.email}));
|
sessionStorage.setItem('current_user', JSON.stringify({id:data.user._id,username:data.user.username,email:data.user.email}));
|
||||||
|
|
||||||
this.$router.push({ name: 'home' });
|
this.$router.push({ name: 'home' });
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<v-app>
|
<v-app>
|
||||||
<v-container class="d-flex justify-center align-center">
|
<v-container class="d-flex justify-center align-center">
|
||||||
<div>
|
<div v-if="!currentUser">
|
||||||
<h1>ยังไม่ได้ลงชื่อเข้าใช้</h1>
|
<h1>ยังไม่ได้ลงชื่อเข้าใช้</h1>
|
||||||
<h2>ลงชื่อเข้าใช้เพื่อบันทึกการตั้งค่าอย่างปลอดภัย</h2>
|
<h2>ลงชื่อเข้าใช้เพื่อบันทึกการตั้งค่าอย่างปลอดภัย</h2>
|
||||||
<v-container class="d-flex justify-center align-center">
|
<v-container class="d-flex justify-center align-center">
|
||||||
|
@ -106,3 +106,13 @@ const display_items = [
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
currentUser: JSON.parse(sessionStorage.getItem('current_user'))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue