feat: add local auth billing and usage management

This commit is contained in:
inman committed 2026-08-12 12:13:06 +08:00
1 parent f642b5e71f
commit 196fdde83f
119 files changed
+15695 -2650

No files matched your search

+13 -1
View File
@@ -1,19 +1,30 @@
import type { PlatformRole } from "@/lib/types";
export type AuthUser = {
id: string;
subject: string;
username?: string;
phone?: string;
displayName: string;
clientId: string;
tenantId?: string;
organizationId?: string;
organizationName?: string;
role?: PlatformRole;
status?: "active" | "disabled";
authorities: string[];
scope: string[];
};
export type AuthMode = "user" | "admin";
export type AuthSession = {
version: 1;
authMode: AuthMode;
user: AuthUser;
issuedAt: number;
expiresAt: number;
sessionVersion?: number;
accessToken?: string;
tokenType?: string;
};
@@ -84,12 +95,13 @@ export async function parseSessionCookieValue(
secret: string,
nowSeconds = Math.floor(Date.now() / 1000)
): Promise<AuthSession | null> {
const session = await parseSignedJsonValue<AuthSession>(value, secret);
const session = await parseSignedJsonValue<Omit<AuthSession, "authMode"> & { authMode?: unknown }>(value, secret);
if (!session || session.version !== 1) return null;
if (!session.user?.id || !session.user.clientId || !session.expiresAt) return null;
if (session.expiresAt <= nowSeconds) return null;
return {
...session,
authMode: session.authMode === "admin" ? "admin" : "user",
accessToken: typeof session.accessToken === "string" ? session.accessToken : undefined,
tokenType: typeof session.tokenType === "string" ? session.tokenType : undefined,
user: {