Skip to content

Commit

Permalink
[PLA-1395] fix user page reload (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlayine authored Nov 3, 2023
1 parent 2eb1f83 commit 32b16f6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
12 changes: 11 additions & 1 deletion resources/js/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import SideNavbar from '~/components/SideNavbar.vue';
import SnackbarGroup from '~/components/SnackbarGroup.vue';
import UserNavbar from '~/components/UserNavbar.vue';
import { computed, watch } from 'vue';
import { useRouter } from 'vue-router';
import { useRoute, useRouter } from 'vue-router';
const appStore = useAppStore();
const router = useRouter();
const route = useRoute();
(async () => {
await appStore.init();
Expand All @@ -50,4 +51,13 @@ watch(
if (!appStore.loggedIn) router.push({ name: 'platform.auth.login' });
}
);
watch(
() => appStore.user,
() => {
if (appStore.isMultiTenant && !appStore.hasValidConfig && route.meta.requiresToken) {
router.push({ name: 'platform.user.settings' });
}
}
);
</script>
2 changes: 1 addition & 1 deletion resources/js/components/SideNavbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="flex flex-shrink-0 items-center px-4">
<CanaryEnjinLogo v-if="canaryHost" class="h-8 w-auto" />
<EnjinLogo v-else class="h-8 w-auto" />
<span class="text-lg font-semibold ml-2">{{ pageTitle() }}</span>
<span class="text-lg font-semibold ml-2 truncate">{{ pageTitle() }}</span>
</div>
<div class="mt-5 flex flex-grow flex-col">
<nav class="flex-1 bg-white" aria-label="Sidebar">
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const appStore = useAppStore();
const advancedMode = ref(appStore.advanced);
const tokenName = ref();
const walletAccount = ref(publicKeyToAddress(appStore.user?.account));
const walletAccount = ref(publicKeyToAddress(appStore.user?.account ?? appStore.config.daemon));
const enableTokenCreate = ref(false);
const enableAccountModify = ref(true);
const loading = ref(appStore.user || !appStore.hasMultiTenantPackage ? false : true);
Expand Down
4 changes: 3 additions & 1 deletion resources/js/components/pages/auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ const login = async () => {
}
if (await appStore.init()) {
snackbar.success({ title: 'Logged in successfully', save: false });
redirectToCollections();
if (appStore.hasValidConfig) {
redirectToCollections();
}
}
} catch (e) {
if (snackbarErrors(e)) return;
Expand Down
7 changes: 5 additions & 2 deletions resources/js/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export const useAppStore = defineStore('app', {
async init() {
try {
this.setConfig();
if (!this.config.url) return false;

if (!this.config.url) {
return false;
}
if (!this.isMultiTenant && !this.config.authorization_token.length) {
return false;
}
Expand Down Expand Up @@ -76,7 +79,7 @@ export const useAppStore = defineStore('app', {
this.addMarketplaceNavigation();
}

if (this.loggedIn && this.hasMultiTenantPackage) {
if (this.loggedIn && this.hasMultiTenantPackage && !this.user) {
await this.getUser();
}

Expand Down
9 changes: 2 additions & 7 deletions resources/js/util/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export function initAuthGuard(router: Router) {
const isLoggedIn = appStore.loggedIn;

const requiresAuth = to.matched.some((record) => record.meta.requiresAuth);
const requiresToken = to.matched.some((record) => record.meta.requiresToken);

if (isMultiTenant) {
if (!appStore.config.url && to.name != 'platform.setup') {
Expand All @@ -23,12 +22,8 @@ export function initAuthGuard(router: Router) {

if (requiresAuth && !isLoggedIn) {
next({ name: 'platform.auth.login' });
} else if (requiresToken && !validConfig) {
next({ name: 'platform.user.settings' });
} else if (to.name == 'platform.auth.login' && isLoggedIn) {
next({ name: 'platform.collections' });
} else {
next();
}
} else {
if (requiresAuth && !isLoggedIn) {
Expand All @@ -37,9 +32,9 @@ export function initAuthGuard(router: Router) {
next({ name: 'platform.setup' });
} else if (to.name == 'platform.setup' && validConfig && isLoggedIn) {
next({ name: 'platform.collections' });
} else {
next();
}
}

next();
});
}

0 comments on commit 32b16f6

Please sign in to comment.