Skip to content

Commit

Permalink
fix: test for auth using token on mounted
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasghodsian committed Aug 23, 2024
1 parent 275dbf8 commit 52b237b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src-frontend/components/modals/AuthModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const toast = useToast();
const apiStore = useApiStore();
const username = ref<string>();
const password = ref<string>();
const showModal = ref<boolean>(true);
const { appContext } = getCurrentInstance()!;
const $cookies = appContext.config.globalProperties.$cookies;
Expand Down Expand Up @@ -52,25 +53,19 @@ const handler = async (): Promise<void> => {
});
}
const isAuth = (): boolean => {
const backendIsAuth = apiStore.auth && !apiStore.authStatus;
if (backendIsAuth == true){
apiStore.testAuth().then(res => {
return false;
onMounted(async (): Promise<void> => {
if ( apiStore.getCookie('token') ){
await apiStore.testAuth().then(res => {
console.log(res);
}).catch(err => {
$cookies.remove('token');
return true;
});
}
return backendIsAuth;
}
});
</script>

<template>
<Dialog :visible="isAuth()" modal :closable="false" class="bg-white"
<Dialog :visible="apiStore.auth && !apiStore.authStatus" modal :closable="false" class="bg-white"
:showHeader="false" :style="{ width: '20rem' }" pt:root:class="!border-0 pt-4 overflow-hidden !bg-minizo-dark !text-white"
pt:mask:class="backdrop-blur-sm">

Expand Down
1 change: 1 addition & 0 deletions src-frontend/stores/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const useApiStore = defineStore('api', {
password: password
}
}).then((response) => {
this.authStatus = true;
return response.data;
}).catch((error) => {
throw error.response;
Expand Down

0 comments on commit 52b237b

Please sign in to comment.