Hi everyone, We are evaluating Ory Network as the...
# ory-network
b
Hi everyone, We are evaluating Ory Network as the IDP in our system and have a question about supporting email change. In our current product, the email is also the login identifier, and the flow works like this: 1. The user clicks a change email button in our web app 2. A modal opens where the user enters the new email 3. The client calls our backend, which then calls the IDP to update the user's email 4. The IDP sends a verification email to the new address 5. After verification, the IDP updates the email on our side through an API call and terminates the user's active sessions We would like to achieve something similar with Ory if possible. We saw that the Patch an Identity API can update the email trait, but we could not find a way to trigger the verification flow afterward. Is there a way to initiate email verification when the email is updated through the API? Or can this be done using Actions or another recommended pattern? Thanks!
m
Hey @billions-translator-90566 The "built-in" behaviour is slightly different but you can use our APIs to achieve something very close to your current implementation. Before I describe that I would recommend the built-in settings flow for email changes. It would work like this 1. Your frontend starts a Settings flow (browser / native). 2. The user enters the new email (trait) in your custom UI driven by the Settings flow’s UI nodes. 3. When the profile (traits) is updated and the email is marked as verifiable in the identity schema, Ory: ◦ Stores the new unverified email in
traits.email
. ◦ Sends a verification code/link to that new email. 4. You can configure “show verification UI after address change” so the user is immediately redirected to the verification screen instead of just seeing a success message. 5. You can use Ory Actions (webhooks) on the
after verification
trigger to call your backend once the email has been verified - your backend can then update its own user record and/or use the admin api to revoke sessions. If you want to use a "custom" way with APIs you can create a new verification flow and submit it
Copy code
# Create verification flow (native)
curl -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    "https://$PROJECT_SLUG.projects.oryapis.com/self-service/verification/api"
Then:
Copy code
# Submit verification flow to send code to the new email
curl -X POST \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -d '{"method":"code","email":"[email protected]"}' \
    "https://$PROJECT_SLUG.projects.oryapis.com/self-service/verification?flow=<flow-id>"
and then use a after verification webhook Action to notify your backend and/or revoke sessions as described above
b
Thanks @magnificent-energy-493 for the quick response! If we go with the custom approach, we should have the new identity email in the after verification action via
ctx.identity.traits.email
, correct?