Fixed auth, NAV, projecttypes,numberranges,tenant,textemplates

This commit is contained in:
2025-09-07 19:26:46 +02:00
parent 34c5764472
commit 949b094490
7 changed files with 129 additions and 125 deletions

View File

@@ -1,4 +1,5 @@
import { defineStore } from "pinia"
import router from "#app/plugins/router";
export const useAuthStore = defineStore("auth", {
state: () => ({
@@ -7,6 +8,7 @@ export const useAuthStore = defineStore("auth", {
tenants: [] as { tenant_id: string; role: string; tenants: { id: string; name: string } }[],
permissions: [] as string[],
activeTenant: null as any,
activeTenantData: null as any,
loading: true as boolean,
}),
@@ -43,18 +45,25 @@ export const useAuthStore = defineStore("auth", {
try {
const me = await useNuxtApp().$api("/api/me", {
headers: { Authorization: `Bearer ${jwt}`,
context: {
jwt
}}
context: {
jwt
}}
})
console.log(me)
this.user = me.user
this.permissions = me.permissions
this.tenants = me.tenants
this.tenants.sort(function (a, b) {
if (a.id < b.id) return -1
if (a.id > b.id) return 1
})
this.profile = me.profile
if(me.activeTenant) {
this.activeTenant = me.activeTenant
this.activeTenantData = me.tenants.find(i => i.id === me.activeTenant)
this.loading = false
} else {
@@ -75,6 +84,7 @@ export const useAuthStore = defineStore("auth", {
})
useCookie("token").value = token
await this.init(token)
navigateTo("/")
},
hasPermission(key: string) {