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

@@ -1,6 +1,7 @@
import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '@/scripts/admin/stores/user'
import { useGlobalStore } from '@/scripts/admin/stores/global'
import { useCompanyStore } from '@/scripts/admin/stores/company'
//admin routes
import AdminRoutes from '@/scripts/admin/admin-router'
@@ -20,9 +21,16 @@ const router = createRouter({
router.beforeEach((to) => {
const userStore = useUserStore()
const globalStore = useGlobalStore()
const companyStore = useCompanyStore()
let ability = to.meta.ability
const { isAppLoaded } = globalStore
if (isAppLoaded && to.meta.requiresAuth && to.name !== 'no.company') {
if (!companyStore.selectedCompany && !(to.meta.isSuperAdmin && userStore.currentUser?.is_super_admin)) {
return { name: 'no.company' }
}
}
if (ability && isAppLoaded && to.meta.requiresAuth) {
if (!userStore.hasAbilities(ability)) {
return { name: 'account.settings' }