1. The user signs in to your app
The user signs in to your app before they can change their primary email address. During the sign-in flow create an OktaAuth
object, which is required to authenticate the user and later change their email.
To learn more about initializing this object and how to integrate the user sign in, see Example Client (opens new window) in Okta Auth Javascript SDK's readme.
2. The user starts the change primary email flow
The user starts the change primary email flow by clicking an Edit link next to the Primary Email Address field. Add an Edit link that gives the user an entry point to change their email.
3. The user submits a new primary email
When the user clicks the Edit link, display a dialog for the user to submit their new email address.
When the user clicks Continue and submits their new email address, create an object of type AddEmailPayload
(opens new window) and set
profile.email
to the new primary email. role
to PRIMARY
, which identifies the email as the primary email address. sendEmail
to true
, which sends an email challenge to the newly added email. The default is true
.
Call addEmail()
(opens new window) and pass in the new AddEmailPayload
object.
Note: If you want to send the email challenge in a separate step, setsendEmail
=false
and call sendEmailChallenge()
(opens new window) after addEmail()
(opens new window).
4. Identity Engine requests new email verification
addEmail()
(opens new window) returns an EmailTransaction
(opens new window) object. The object has a status
of UNVERIFIED
that indicates that the user needs to verify their identity with the new email.
Build the logic that handles this response and sends the user to a dialog where they enter the OTP.
5. The user verifies their identity with the new email
The user opens the email sent by Identity Engine and copies the one-time passcode (OTP) to your app. Create a dialog to allow the user to enter and submit the OTP.
When the user submits the OTP, create an object of type VerificationPayload
(opens new window) and set verificationCode
to the OTP entered by the user.
Call verify()
(opens new window) on the EmailTransaction
returned from the previous step and pass in the new VerificationPayload
object. Wrap the method call in a try...catch
statement to catch invalid OTPs and other API exceptions raised from EmailTransaction.verify()
.
6. Your app handles a successful identity verification
When the OTP is valid and the email change completes successfully, EmailTransaction.verify()
returns no data and completes without exception. Your app should close the change email dialog, refresh the main page, and display the new primary email and any other profile information.