Fix tenant normalization types and add QR code typings (#514)

This commit is contained in:
shenlan 2025-10-13 14:14:26 +08:00 committed by GitHub
parent b8e251db31
commit 0c73cfb3c6
3 changed files with 41 additions and 22 deletions

View File

@ -120,19 +120,19 @@ export async function GET(request: NextRequest) {
return null
}
const label =
typeof tenant.name === 'string' && tenant.name.trim().length > 0
? tenant.name.trim()
: undefined
const roleValue =
typeof tenant.role === 'string' && tenant.role.trim().length > 0
? tenant.role.trim().toLowerCase()
: undefined
return {
const normalizedTenant: { id: string; name?: string; role?: string } = {
id: identifier,
name: label,
role: roleValue,
}
if (typeof tenant.name === 'string' && tenant.name.trim().length > 0) {
normalizedTenant.name = tenant.name.trim()
}
if (typeof tenant.role === 'string' && tenant.role.trim().length > 0) {
normalizedTenant.role = tenant.role.trim().toLowerCase()
}
return normalizedTenant
})
.filter((tenant): tenant is { id: string; name?: string; role?: string } => Boolean(tenant))
: undefined

View File

@ -187,19 +187,20 @@ async function fetchSessionUser(): Promise<User | null> {
if (!identifier) {
return null
}
const label =
typeof tenant.name === 'string' && tenant.name.trim().length > 0
? tenant.name.trim()
: undefined
const roleValue =
typeof tenant.role === 'string' && tenant.role.trim().length > 0
? normalizeRole(tenant.role)
: undefined
return {
const normalizedTenant: TenantMembership = {
id: identifier,
name: label,
role: roleValue,
}
if (typeof tenant.name === 'string' && tenant.name.trim().length > 0) {
normalizedTenant.name = tenant.name.trim()
}
if (typeof tenant.role === 'string' && tenant.role.trim().length > 0) {
normalizedTenant.role = normalizeRole(tenant.role)
}
return normalizedTenant
})
.filter((tenant): tenant is TenantMembership => Boolean(tenant))
: undefined

18
ui/homepage/types/qrcode.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
declare module 'qrcode' {
export type ErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H'
export type QRCodeColorOptions = {
dark?: string
light?: string
}
export type QRCodeToDataURLOptions = {
errorCorrectionLevel?: ErrorCorrectionLevel
margin?: number
scale?: number
width?: number
color?: QRCodeColorOptions
}
export function toDataURL(text: string, options?: QRCodeToDataURLOptions): Promise<string>
}