File
Blob: src/client/lib/handle.ts
| 1 | // Mirrors the server helper in src/worker/auth/index.ts so rows with a |
| 2 | // null `preferredUsername` display the same slug the OIDC claim emits. |
| 3 | // When the column is set, it wins on both sides. Shared by the account |
| 4 | // hub and /account/profile. |
| 5 | export const fallbackHandle = (u: { name?: string | null; email: string }): string => { |
| 6 | const slug = (s: string) => |
| 7 | s |
| 8 | .toLowerCase() |
| 9 | .normalize("NFKD") |
| 10 | .replace(/[^a-z0-9]+/g, "-") |
| 11 | .replace(/^-+|-+$/g, ""); |
| 12 | if (u.name?.trim()) { |
| 13 | const fromName = slug(u.name); |
| 14 | if (fromName) return fromName; |
| 15 | } |
| 16 | return slug(u.email.split("@")[0] ?? "") || "user"; |
| 17 | }; |