Skip to content
This repository has been archived by the owner on Nov 4, 2020. It is now read-only.

Latest commit

 

History

History
79 lines (57 loc) · 2.49 KB

File metadata and controls

79 lines (57 loc) · 2.49 KB
description
initiates the update email flow that allows a user to change to a new email

updateEmail

Arguments

updateEmail({ email, showUI? = true })

  • email (String): The new email to update to.
  • showUI?(Boolean): If true, 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.

Returns

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.

Example

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!
}

Error Handling

Relevant Error Codes****

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;
    }
  }
}

Events

  • 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 if showUI: true.