AdvisoryBuilderWorkshop / frontend /src /lib /userDisplayName.ts
NeonClary's picture
Deploy tutorial feature and recent fixes
d8808e7 verified
Raw
History Blame Contribute Delete
556 Bytes
import type { User } from '../context/AuthContext'
/** Best display string for autofill: "First Last", else email local part before @. */
export function defaultDisplayNameFromUser(user: User | null): string {
if (!user) return ''
const full = [user.firstName, user.lastName]
.map((s) => (typeof s === 'string' ? s.trim() : ''))
.filter(Boolean)
.join(' ')
.trim()
if (full) return full
const email = user.email?.trim() ?? ''
const at = email.indexOf('@')
if (at > 0) return email.slice(0, at)
return email
}