File size: 556 Bytes
d8808e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
}