description |
---|
initiates the update email flow that allows a user to change to a new email |
updateEmail({ email, showUI? = true })
email
(String): The new email to update to.showUI?
(Boolean): Iftrue
, show an out-of-the-box pending UI includes instructions on which step of the confirmation process the user is on. Dismisses automatically when the process is complete.
PromiEvent<boolean>
: The promise resolves with a true boolean value if update email is successful and rejects with a specific error code if the request fails.
import { Magic } from 'magic-sdk';
const m = new Magic('API_KEY');
// Initiates the flow to update a user's current email to a new one.
try {
...
/* Assuming user is logged in */
await magic.user.updateEmail({ email: '[email protected]' });
} catch {
// Handle errors if required!
}
/**
* Initiates the flow to update a user's current email to a new one,
* without showing an out-of-the box UI.
*/
try {
/* Assuming user is logged in */
await magic.user.updateEmail({ email: '[email protected]', showUI: false });
} catch {
// Handle errors if required!
}
To achieve a fully white-labeled experience, you will need to implement some custom error handling according to your UI needs. Here's a short example to illustrate how errors can be caught and identified by their code:
import { Magic, RPCError, RPCErrorCode } from 'magic-sdk';
const m = new Magic('API_KEY');
try {
await m.user.updateEmail({ email: '[email protected]', showUI: false });
} catch(err) {
if (err instanceof RPCError) {
switch(err.code) {
case RPCErrorCode.UpdateEmailFailed:
// Handle errors accordingly :)
break;
}
}
}
new-email-confirmed
: Dispatched when the magic link has been clicked from the user’s new email address.email-sent
: Dispatched when the magic link email has been successfully sent from the Magic Link server to the user’s new email address.email-not-deliverable
: Dispatched if the magic link email is unable to be delivered to the user’s new email address.old-email-confirmed
: Dispatched when the magic link has been clicked from the user’s previous email address.retry
: Dispatched when the user restarts the flow. This can only happen ifshowUI: true
.