Move login-error hash check to App.vue

This commit is contained in:
Maciej Pędzich 2023-05-28 09:10:32 +02:00
parent cc752dd7ce
commit 4de34ead70
2 changed files with 10 additions and 18 deletions

View File

@ -15,11 +15,18 @@ const { showSnackbar } = useSnackbar();
onMounted(async () => { onMounted(async () => {
await router.isReady(); await router.isReady();
if (router.currentRoute.value.hash === '#login-success') { const loginStatusHashes = ['#login-error', '#login-success'];
const routeHash = router.currentRoute.value.hash;
if (loginStatusHashes.includes(routeHash)) {
localStorage.removeItem('redirectPath'); localStorage.removeItem('redirectPath');
showSnackbar({ showSnackbar({
status: 'success', status: routeHash.replace('#login-', '') as 'error' | 'success',
message: "You're logged in!" message:
routeHash === '#login-error'
? 'Failed to log you in'
: "You're logged in"
}); });
} }
}); });

View File

@ -1,22 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { useAuth } from '@/composables/useAuth'; import { useAuth } from '@/composables/useAuth';
import { useSnackbar } from '@/composables/useSnackbar';
const route = useRoute();
const { logIn } = useAuth(); const { logIn } = useAuth();
const { showSnackbar } = useSnackbar();
onMounted(() => {
if (route.hash === '#login-error') {
showSnackbar({
status: 'error',
message: 'Failed to log you in.'
});
}
});
</script> </script>
<template> <template>