Files
cameleer-saas/ui/src/auth/useOrganization.ts
hsiegeln c96faa4f3f
All checks were successful
CI / build (push) Successful in 1m0s
CI / docker (push) Successful in 55s
fix: display username in UI, fix license limits key mismatch
- Read user profile from Logto ID token in OrgResolver, store in
  Zustand org store, display in sidebar footer and TopBar avatar
- Fix license limits showing "—" by aligning frontend LIMIT_LABELS
  keys with backend snake_case convention (max_agents, retention_days,
  max_environments)
- Bump @cameleer/design-system to v0.1.38 (font-size floor)
- Add dev volume mount for local UI hot-reload without image rebuild

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 12:20:40 +02:00

44 lines
1.4 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[];
scopes: Set<string>;
username: string | null;
setCurrentOrg: (orgId: string | null) => void;
setOrganizations: (orgs: OrgInfo[]) => void;
setScopes: (scopes: Set<string>) => void;
setUsername: (name: string | null) => void;
}
export const useOrgStore = create<OrgState>((set, get) => ({
currentOrgId: null,
currentTenantId: null,
organizations: [],
scopes: new Set(),
username: null,
setUsername: (name) => set({ username: name }),
setCurrentOrg: (orgId) => {
const org = get().organizations.find((o) => o.id === orgId);
set({ currentOrgId: orgId, currentTenantId: org?.tenantId ?? null });
},
setOrganizations: (orgs) => {
const { currentOrgId } = get();
const match = currentOrgId ? orgs.find((o) => o.id === currentOrgId) : null;
set({
organizations: orgs,
// Re-resolve tenantId when org list is enriched (e.g., OrgResolver adds tenantId)
currentTenantId: match?.tenantId ?? get().currentTenantId,
});
},
setScopes: (scopes) => set({ scopes }),
}));