-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathuser.ts
33 lines (25 loc) · 862 Bytes
/
user.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
type NameHelperParams = {
firstName?: string | null;
lastName?: string | null;
name?: string | null;
};
export const getFullName = ({ firstName, lastName, name }: NameHelperParams) =>
name || [firstName, lastName].join(' ').trim() || '';
export const getInitials = ({ firstName, lastName, name }: NameHelperParams) =>
[(firstName || '')[0], (lastName || '')[0]].join('').trim() || (name || '')[0];
import type { UserResource } from '@clerk/types';
export const getIdentifier = (user: Partial<UserResource>): string => {
if (user.username) {
return user.username;
}
if (user.primaryEmailAddress) {
return user.primaryEmailAddress.emailAddress;
}
if (user.primaryPhoneNumber) {
return user.primaryPhoneNumber.phoneNumber;
}
if (user.primaryWeb3Wallet) {
return user.primaryWeb3Wallet.web3Wallet;
}
return '';
};