fix login and create logout

fix login to login by email password
This commit is contained in:
NekoVari 2023-11-18 18:06:27 +07:00
parent 19b4d18941
commit 48e29ee9fd
3 changed files with 795 additions and 7 deletions

View file

@ -12,8 +12,8 @@
<div class="mx-5">
<v-text-field
class="username"
v-model="input.username"
class="email"
v-model="input.email"
label="อีเมล"
variant="solo"
>
@ -85,14 +85,14 @@ export default {
return {
pageTitle: 'ลงชื่อเข้าใช้',
input: {
username: '',
email: '',
password: ''
}
};
},
methods: {
login() {
if (this.input.username !== '' && this.input.password !== '') {
if (this.input.email !== '' && this.input.password !== '') {
console.log('Authenticated: Checking with Backend');
fetch(`https://little-lines-backend.techtransthai.org/api/users/login`, {
method: "POST",
@ -100,7 +100,7 @@ export default {
"Content-Type": "application/json",
},
body: JSON.stringify({
username: this.input.username,
email: this.input.email,
password: this.input.password,
}),
})
@ -121,7 +121,7 @@ export default {
// Handle the error, e.g., display an error message to the user
});
} else {
console.log('Username and Password cannot be empty');
console.log('Email and Password cannot be empty');
}
}
}

View file

@ -55,7 +55,7 @@
</v-list-item>
</v-list>
<v-btn class = "ma-2 mt-3" width="100%"
<v-btn @click.prevent="logout" class = "ma-2 mt-3" width="100%"
color="red">
ลงชอออก
</v-btn>
@ -69,6 +69,8 @@
<script setup>
import {RouterLink} from 'vue-router';
import { VContainer } from 'vuetify/lib/components/index.mjs';
import router from '@/plugins/router'
const account_items = [
{ text: 'ตั้งค่าบัญชี',
@ -90,5 +92,17 @@ const display_items = [
icon: 'mdi-chevron-right',}
]
function logout() {
if (sessionStorage.getItem('current_user')){
console.log('loging out...');
fetch(`https://little-lines-backend.techtransthai.org/api/users/logout`, {
method: "GET"
}).then(()=>{
console.log('loged out');
sessionStorage.removeItem('current_user');
router.push({ name: 'home' });
})
}
}
</script>