Appearance
Updating user accounts
Updating emails
To update a user's email, use the useUpdateEmail
hook.
tsx
const {sendCode, updateEmail} = useUpdateEmail();
Send an OTP
First, use the sendCode
method to send an OTP verification code to the user's new email address.
Parameter | Type | Description |
---|---|---|
newEmailAddress | string | The new email address to be validated. |
This will send a one-time passcode to the new email address, which the user will need to enter to verify it and confirm the update. The method returns a Promise
that resolves if the code was sent successfully, and rejects otherwise.
tsx
import {useUpdateEmail} from '@privy-io/expo';
function UpdateEmailForm() {
const {sendCode} = useUpdateEmail();
const [newEmailAddress, setNewEmailAddress] = useState('');
return (
<View>
<Input value={newEmailAddress} onChangeText={setNewEmailAddress} />
<Button onPress={() => sendCode({newEmailAddress})}>Send code</Button>
</View>
);
}
Verify the OTP
Prompt the user for the OTP they received and verify the OTP by passing it to the updateEmail
method on the same hook.
The method returns a Promise
that resolves with the updated user object if the update was successful, and rejects otherwise.
Parameter | Type | Description |
---|---|---|
newEmailAddress | string | The new email address to set. |
code | string | The one time code received on the new email address. |
tsx
import {useUpdateEmail} from '@privy-io/expo';
function ConfirmEmailUpdateForm() {
const {updateEmail} = useUpdateEmail();
const [code, setCode] = useState('');
return (
<View>
<Input value={code} onChangeText={setCode} />
<Button onPress={() => updateEmail({code, newEmailAddress})}>Confirm</Button>
</View>
);
}
Updating phone numbers
To update a user's phone number, use the useUpdatePhone
hook.
tsx
const {sendCode, updatePhone} = useUpdatePhone();
Send an OTP
First, use the sendCode
method to send an OTP verification code to the user's new phone number.
Parameter | Type | Description |
---|---|---|
newPhoneNumber | string | The new phone number to be validated. |
This will send a one-time passcode to the new phone number, which the user will need to enter to verify it and confirm the update. The method returns a Promise
that resolves if the code was sent successfully, and rejects otherwise.
tsx
import {useUpdatePhone} from '@privy-io/expo';
function UpdatePhoneForm() {
const {sendCode} = useUpdatePhone();
const [newPhoneNumber, setNewPhoneNumber] = useState('');
return (
<View>
<Input value={newPhoneNumber} onChangeText={setNewPhoneNumber} />
<Button onPress={() => sendCode({newPhoneNumber})}>Send code</Button>
</View>
);
}
Verify the OTP
Prompt the user for the OTP they received and verify the OTP by passing it to the updatePhone
method on the same hook.
The method returns a Promise
that resolves with the updated user object if the update was successful, and rejects otherwise.
Parameter | Type | Description |
---|---|---|
newPhoneNumber | string | The new phone number to set. |
code | string | The one time code received on the new phone number. |
tsx
import {useUpdatePhone} from '@privy-io/expo';
function ConfirmPhoneUpdateForm() {
const {updatePhone} = useUpdatePhone();
const [code, setCode] = useState('');
return (
<View>
<Input value={code} onChangeText={setCode} />
<Button onPress={() => updatePhone({code, newPhoneNumber})}>Confirm</Button>
</View>
);
}