Files
moeka-project/server/packages/auth-shared/src/session.ts
T
2026-08-26 20:13:10 +08:00

39 lines
980 B
TypeScript

/** Authenticated principal exposed to AIRI resource handlers. */
export interface AuthSession {
user: {
id: string
name: string
email: string
emailVerified: boolean
image?: string | null
banned?: boolean | null
banReason?: string | null
banExpires?: Date | null
lastSeenAt?: Date | null
createdAt: Date
updatedAt: Date
}
session: {
id: string
token: string
userId: string
expiresAt: Date
createdAt: Date
updatedAt: Date
ipAddress?: string | null
userAgent?: string | null
}
}
/**
* Evaluates Better Auth's persisted ban fields without requiring its runtime.
* Expired temporary bans are treated as inactive on stateless JWT paths.
*/
export function isUserBannedNow(user: { banned?: boolean | null, banExpires?: Date | string | null }): boolean {
if (!user.banned)
return false
if (user.banExpires == null)
return true
return new Date(user.banExpires).getTime() > Date.now()
}