import type { DefaultSession } from "next-auth" import type { Permission, Role } from "@/shared/types/permissions" declare module "next-auth" { interface User { /** 主要角色(向后兼容) */ role?: string /** 用户拥有的全部角色名 */ roles?: string[] } interface Session { user: DefaultSession["user"] & { id: string role: string // kept for backward compatibility roles: Role[] permissions: Permission[] onboarded: boolean } } } declare module "next-auth/jwt" { interface JWT { id: string role: string // kept for backward compatibility roles: Role[] /** * 权限位图(base36 字符串,audit-P1-7)。 * * 由 `encodePermissionsBitmap()` 编码生成,约 14 字符, * 相比 `permissions: Permission[]` JSON 数组(~1.1KB)显著减小 JWT 体积。 * * proxy.ts 边缘运行时直接通过 `hasPermissionInBitmap()` 检查权限, * 无需解码为完整数组。 * * Session callback 中通过 `decodePermissionsBitmap()` 还原为 Permission[] * 供服务端 `getAuthContext()` 和客户端 `usePermission()` 使用。 */ permissionsBitmap: string /** * @deprecated 仅用于向后兼容,新代码应使用 `permissionsBitmap`。 * Session callback 已自动从 bitmap 解码并填充到 `session.user.permissions`, * 业务代码无需直接读取 `token.permissions`。 * 在 JWT 中保留此字段会导致 token 体积膨胀,未来版本将移除。 */ permissions?: Permission[] onboarded: boolean } }