Create user metadata
These methods on the User
object help you create data for the user, such as createEmailAddress()
and createPhoneNumber()
.
The following examples assume that you have followed the quickstart in order to add Clerk to your JavaScript application.
createEmailAddress()
Adds an email address for the user. A new EmailAddress
will be created and associated with the user.
- Name
email
- Type
string
- Description
The value of the email address
Example
The following example adds test@test.com
as an email address for the user. If the user is not signed in, the user will be prompted to sign in.
createPhoneNumber()
Adds a phone number for the user. A new PhoneNumber
will be created and associated with the user.
- Name
phoneNumber
- Type
string
- Description
The value of the phone number, in E.164 format.
Example
The following example adds 15551234567
as a phone number for the user. If the user is not signed in, the user will be prompted to sign in.
createWeb3Wallet()
Adds a Web3 wallet for the user. A new Web3Wallet
will be created and associated with the user.
- Name
web3Wallet
- Type
string
- Description
The Web3 wallet address, made up of 0x + 40 hexadecimal characters.
Example
The following example adds 0x0123456789ABCDEF0123456789ABCDEF01234567
as a Web3 wallet for the user. If the user is not signed in, the user will be prompted to sign in.
createExternalAccount()
Adds an external account for the user. A new ExternalAccount
will be created and associated with the user. This method is useful if you want to allow an already signed-in user to connect their account with an external provider, such as Facebook, GitHub, etc., so that they can sign in with that provider in the future.
- Name
strategy
- Type
OAuthStrategy
- Description
The strategy corresponding to the OAuth provider. For example:
oauth_facebook
,oauth_github
, etc.
- Name
redirectUrl?
- Type
string
- Description
The URL to redirect back to once the OAuth flow has succeeded or failed.
- Name
additionalScopes?
- Type
string[]
- Description
Any additional scopes you would like your user to be prompted to approve.
Example
After calling createExternalAccount
, the initial state
of the returned ExternalAccount
will be unverified
. To initiate the connection with the external provider, redirect the user to the externalAccount.verification.externalVerificationRedirectURL
contained in the result of createExternalAccount
.
Upon return, inspect within the user.externalAccounts
the entry that corresponds to the requested strategy:
- If the connection succeeded, then
externalAccount.verification.status
will beverified
. - If the connection failed, then the
externalAccount.verification.status
will not beverified
and theexternalAccount.verification.error
will contain the error encountered, which you can present to the user. To learn more about the properties available onverification
, see theverification
reference.
The following example demonstrates how to add a Notion account as an external account for the user. When the user selects the "Add Notion as a social connection" button, the user will be redirected to Notion to connect their account. After connecting their account, they will be redirected to the /
route of your application, and the status of the connection will be displayed.
Feedback
Last updated on