mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-18 10:44:08 +00:00
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:
8
resources/scripts/router/index.js
vendored
8
resources/scripts/router/index.js
vendored
@@ -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' }
|
||||
|
||||
Reference in New Issue
Block a user