Add frontend handling for users without a company

Make setSelectedCompany null-safe and clear stale localStorage.
Conditionally initialize company store state in bootstrap. Add
router guard to redirect no-company users to NoCompanyView while
allowing super admins through. Hide sidebar when no company.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Darko Gjorgjijoski
2026-04-04 00:36:00 +02:00
parent fae59221d3
commit c3a59a46db
5 changed files with 46 additions and 15 deletions

View File

@@ -6,12 +6,15 @@
<SiteHeader />
<SiteSidebar />
<SiteSidebar v-if="hasCompany" />
<ExchangeRateBulkUpdateModal />
<main
class="h-screen h-screen-ios overflow-y-auto md:pl-56 xl:pl-64 min-h-0"
:class="[
'h-screen h-screen-ios overflow-y-auto min-h-0',
hasCompany ? 'md:pl-56 xl:pl-64' : '',
]"
>
<div class="pt-16 pb-16">
<router-view />
@@ -51,8 +54,19 @@ const isAppLoaded = computed(() => {
return globalStore.isAppLoaded
})
const hasCompany = computed(() => {
return !!companyStore.selectedCompany || !!userStore.currentUser?.is_super_admin
})
onMounted(() => {
globalStore.bootstrap().then((res) => {
if (!res.data.current_company && !res.data.current_user.is_super_admin) {
if (route.name !== 'no.company') {
router.push({ name: 'no.company' })
}
return
}
if (route.meta.ability && !userStore.hasAbilities(route.meta.ability)) {
router.push({ name: 'account.settings' })
} else if (route.meta.isSuperAdmin && !userStore.currentUser.is_super_admin) {