32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
|
|
import { create } from 'zustand';
|
||
|
|
|
||
|
|
export interface OrgInfo {
|
||
|
|
id: string; // Logto org ID (for token scoping)
|
||
|
|
name: string;
|
||
|
|
slug?: string;
|
||
|
|
tenantId?: string; // DB tenant UUID (for API calls)
|
||
|
|
}
|
||
|
|
|
||
|
|
interface OrgState {
|
||
|
|
currentOrgId: string | null; // Logto org ID — used for getAccessToken(resource, orgId)
|
||
|
|
currentTenantId: string | null; // DB UUID — used for API calls like /api/tenants/{id}
|
||
|
|
organizations: OrgInfo[];
|
||
|
|
isPlatformAdmin: boolean;
|
||
|
|
setCurrentOrg: (orgId: string | null) => void;
|
||
|
|
setOrganizations: (orgs: OrgInfo[]) => void;
|
||
|
|
setIsPlatformAdmin: (value: boolean) => void;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const useOrgStore = create<OrgState>((set, get) => ({
|
||
|
|
currentOrgId: null,
|
||
|
|
currentTenantId: null,
|
||
|
|
organizations: [],
|
||
|
|
isPlatformAdmin: false,
|
||
|
|
setCurrentOrg: (orgId) => {
|
||
|
|
const org = get().organizations.find((o) => o.id === orgId);
|
||
|
|
set({ currentOrgId: orgId, currentTenantId: org?.tenantId ?? null });
|
||
|
|
},
|
||
|
|
setOrganizations: (orgs) => set({ organizations: orgs }),
|
||
|
|
setIsPlatformAdmin: (value) => set({ isPlatformAdmin: value }),
|
||
|
|
}));
|