Skip to content

Commit

Permalink
hotfix - login page (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlayine authored Aug 21, 2023
1 parent da0d321 commit 4919859
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion resources/js/components/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="h-full flex flex-row">
<SideNavbar v-if="appStore.hasValidConfig" />
<SideNavbar v-if="appStore.loggedIn" />
<SnackbarGroup />

<div class="flex flex-col w-full overflow-hidden">
Expand Down
11 changes: 9 additions & 2 deletions resources/js/components/pages/auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

<script setup lang="ts">
import { Form } from 'vee-validate';
import { ref } from 'vue';
import { ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useAppStore } from '~/store';
import Btn from '~/components/Btn.vue';
Expand Down Expand Up @@ -119,8 +119,15 @@ const checkVerified = () => {
(async () => {
checkVerified();
if (appStore.hasValidConfig) {
if (appStore.loggedIn) {
redirectToCollections();
}
})();
watch(
() => appStore.hasValidConfig,
() => {
if (appStore.hasValidConfig) router.push({ name: 'platform.collections' });
}
);
</script>
2 changes: 1 addition & 1 deletion resources/js/components/pages/auth/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const register = async () => {
};
(async () => {
if (appStore.hasValidConfig) {
if (appStore.loggedIn) {
redirectToLogin();
}
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const requestReset = async () => {
};
(async () => {
if (appStore.hasValidConfig) {
if (appStore.loggedIn) {
redirectToCollections();
}
})();
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/pages/auth/ResetPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const resetPassword = async () => {
(async () => {
email.value = route.query.email as string;
if (appStore.hasValidConfig) {
if (appStore.loggedIn) {
redirectToCollections();
}
})();
Expand Down
13 changes: 7 additions & 6 deletions resources/js/util/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function initAuthGuard(router: Router) {

const validConfig = appStore.hasValidConfig;
const isMultiTenant = appStore.isMultiTenant;
const isLoggedIn = appStore.loggedIn;

const requiresAuth = to.matched.some((record) => record.meta.requiresAuth);
const requiresToken = to.matched.some((record) => record.meta.requiresToken);
Expand All @@ -20,21 +21,21 @@ export function initAuthGuard(router: Router) {
return;
}

if (requiresAuth && !validConfig) {
if (requiresAuth && !isLoggedIn) {
next({ name: 'platform.auth.login' });
} else if (requiresToken && appStore.user && !validConfig) {
} else if (requiresToken && appStore.user && !isLoggedIn) {
next({ name: 'platform.user.settings' });
} else if (to.name == 'platform.auth.login' && validConfig) {
} else if (to.name == 'platform.auth.login' && isLoggedIn) {
next({ name: 'platform.collections' });
} else {
next();
}
} else {
if (requiresAuth && !validConfig) {
if (requiresAuth && !isLoggedIn) {
next({ name: 'platform.setup' });
} else if (to.name == 'platform.auth.login' && !validConfig) {
} else if (to.name == 'platform.auth.login' && !isLoggedIn) {
next({ name: 'platform.setup' });
} else if (to.name == 'platform.setup' && validConfig) {
} else if (to.name == 'platform.setup' && validConfig && isLoggedIn) {
next({ name: 'platform.collections' });
} else {
next();
Expand Down

0 comments on commit 4919859

Please sign in to comment.