All files / src shared-auth.ts

0% Statements 0/0
0% Branches 1/1
0% Functions 1/1
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52                                                                                                       
export type UserRole = "user" | "admin";
export type PlanId = "free" | "pro" | "team" | "enterprise";
 
export interface SnapbackAuthContext {
	// Identity
	userId: string;
	email: string;
	role: UserRole;
	name?: string; // From better-auth user table
	createdAt?: Date; // From better-auth user table
 
	// Multi-tenant
	orgId?: string;
	orgRole?: "owner" | "admin" | "member";
 
	// Auth mechanism
	sessionId?: string;
	expiresAt?: Date;
	authenticatedVia: "session" | "accessToken" | "apiKey";
 
	// API key metadata (only if authenticatedVia === "apiKey")
	apiKeyId?: string;
	apiKeyScopes?: string[];
 
	// Commercial
	plan: PlanId;
 
	// Auth state enrichment (optional, non-breaking)
	emailVerified?: boolean;
	twoFactorEnabled?: boolean;
	passkeyRegistered?: boolean;
}
 
export interface SnapbackAuth {
	getContextFromRequest(req: Request): Promise<SnapbackAuthContext | null>;
 
	requireAuth(
		req: Request,
		options?: {
			roles?: UserRole[];
			scopes?: string[];
		},
	): Promise<SnapbackAuthContext>;
 
	getOrganizationContext(ctx: SnapbackAuthContext): Promise<{
		id: string;
		name: string;
		slug: string;
		role: string;
	} | null>;
}