logout method

This commit is contained in:
='fauz 2025-10-20 11:41:55 +07:00
parent 2882b64d25
commit a9933ccc8e
2 changed files with 11 additions and 12 deletions

View File

@ -354,6 +354,7 @@
import { getContent } from '@/services/content'; import { getContent } from '@/services/content';
import { getMissions,getMissionLogs, createMissionLog } from '@/services/missions'; import { getMissions,getMissionLogs, createMissionLog } from '@/services/missions';
import { useAuthStore } from '@/stores/auth' import { useAuthStore } from '@/stores/auth'
import { nextTick } from 'vue';
export default { export default {
name: "App", name: "App",
@ -585,7 +586,16 @@ export default {
}); });
mission.userStatus = 'in_progress'; mission.userStatus = 'in_progress';
} },
async handleLogout() {
try {
await this.authStore.logout();
await nextTick();
this.$router.push("/login");
} catch (err) {
console.error("Logout failed:", err);
}
},
}, },
mounted() { mounted() {
this.getMission(); this.getMission();
@ -605,14 +615,4 @@ export default {
} }
} }
}; };
</script>
<script setup>
// import { useAuthStore } from '@/stores/auth'
import { useRouter } from 'vue-router'
const router = useRouter()
const auth = useAuthStore()
const handleLogout = () => {
auth.logout()
router.push('/login')
}
</script> </script>

View File

@ -55,7 +55,6 @@ export const useAuthStore = defineStore('auth', {
console.log("✅ Logged in as:", this.user.username); console.log("✅ Logged in as:", this.user.username);
}, },
async logout() { async logout() {
// revoke token
if(this.token){ if(this.token){
await axios.post(this.baseUrl + '/oauth/revoke_token/', { await axios.post(this.baseUrl + '/oauth/revoke_token/', {
token: this.token, token: this.token,