- Create pre-configured Hogan Lovells tenant with demo flag and auto_assign_domains: ["hoganlovells.com"] - Add POST /api/tenants/auto-assign endpoint: checks email domain against tenant settings, auto-assigns user as associate if match - Add AutoAssignByDomain to TenantService - Update registration flow: after signup, check auto-assign before showing tenant creation form. Skip tenant creation if auto-assigned. - Add DemoBanner component shown when tenant.settings.demo is true - Extend GET /api/me to return is_demo flag from tenant settings
31 lines
678 B
TypeScript
31 lines
678 B
TypeScript
"use client";
|
|
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { api } from "@/lib/api";
|
|
import type { UserInfo } from "@/lib/types";
|
|
|
|
export function usePermissions() {
|
|
const { data, isLoading } = useQuery({
|
|
queryKey: ["me"],
|
|
queryFn: () => api.get<UserInfo>("/me"),
|
|
staleTime: 60 * 1000,
|
|
});
|
|
|
|
const role = data?.role ?? null;
|
|
const permissions = data?.permissions ?? [];
|
|
|
|
function can(permission: string): boolean {
|
|
return permissions.includes(permission);
|
|
}
|
|
|
|
return {
|
|
role,
|
|
permissions,
|
|
can,
|
|
isLoading,
|
|
userId: data?.user_id ?? null,
|
|
tenantId: data?.tenant_id ?? null,
|
|
isDemo: data?.is_demo ?? false,
|
|
};
|
|
}
|