Become a Pro / website · becomeapro.ai / src / lib / display-name.ts
| 1 | type DisplayUser = { name?: string | null; provider?: string | null }; |
| 2 | |
| 3 | export const FALLBACK_NAME = "Builder"; |
| 4 | |
| 5 | export function displayName(user: DisplayUser): string { |
| 6 | const name = user.name?.trim(); |
| 7 | return name && !name.includes("@") ? name : FALLBACK_NAME; |
| 8 | } |
| 9 | |
| 10 | export function firstName(user: DisplayUser): string { |
| 11 | return displayName(user).split(/\s+/)[0]; |
| 12 | } |
| 13 | |
| 14 | export function providerLabel(user: DisplayUser): string | null { |
| 15 | if (user.provider === "apple") return "Apple"; |
| 16 | if (user.provider === "google") return "Google"; |
| 17 | return null; |
| 18 | } |