codeflash-internal/js/cf-api/auth0-mgmt.ts
Kevin Turcios d7a8b8f227
perf: fix CI build + lazy-load heavy libs + parallelize DB queries (#2601)
## Summary
- **Fix CI build failure**: Auth0Client crashes during Next.js
prerendering when env vars aren't set. Returns a no-op stub (`getSession
→ null`) when domain is missing — semantically correct for static
generation
- **Lazy-load markdown libs (~260kb)**: ReactMarkdown, remarkGfm, and
react-syntax-highlighter were eagerly imported in monaco-diff-viewer but
only rendered when user expands "Generated Tests". Extracted into a
dynamic component
- **Parallelize repo detail query**: `getRepositoryById` ran the
activity count sequentially after the repo lookup. Since `repoId` is
already available, all three queries now run in parallel

## Test plan
- [ ] CI `build` check passes (was failing since #2598)
- [ ] Trace page still renders generated tests correctly when expanded
- [ ] Repository detail page loads correctly with activity status
2026-04-13 11:03:05 -05:00

29 lines
917 B
TypeScript

import { ManagementClient } from "auth0"
// Create a singleton instance or allow injection
let managementClient: ManagementClient | null = null
export function getManagementClient(): ManagementClient {
managementClient ||= new ManagementClient({
domain: process.env.AUTH0_ISSUER_BASE_URL ?? "",
clientId: process.env.AUTH0_MANAGEMENT_CLIENT_ID ?? "",
clientSecret: process.env.AUTH0_MANAGEMENT_CLIENT_SECRET ?? "",
})
return managementClient
}
// For testing purposes
export function setManagementClient(client: ManagementClient | null) {
managementClient = client
}
export async function userNickname(userId: string): Promise<string | null> {
const m = getManagementClient()
try {
const user = await m.users.get({ id: userId, fields: "nickname" })
return user.data?.nickname ?? null
} catch (error) {
console.log("Error getting user nickname:", error)
return null
}
}