Change Email
Change email
You can change email of the user by calling the changeEmail
method.
- Javascript
- Dart
let currentPassword = "123456";
let newEmail = "[email protected]";
// Change email of the user
const result = await altogic.auth.changeEmail(currentPassword, newEmail);
final currentPassword = "123456";
final newEmail = "[email protected]";
// Change email of the user
final result = await altogic.auth.changeEmail(currentPassword, newEmail);
Example response
{
"user": {
"_id": "6235f78c0874df80013caea2",
"provider": "altogic",
"providerUserId": "6235f78c0874df80013caea2",
"email": "[email protected]",
"signUpAt": "2022-03-19T15:32:28.958Z",
"lastLoginAt": "2022-03-19T15:38:42.093Z",
"emailVerified": true,
"name": "Rooby"
},
"errors": null
}
info
If email confirmation is enabled in your App settings → Authentication view of Designer
- It sends a confirmation email to the new email address with a link for the user to click and returns the current user's info.
- Until the user clicks on the link, the user's email address will not be changed to the new one.
- Once user click on the link, the user's email address will be changed to the new one and redirect user to the Redirect URL with an action=change-email query string parameter.
http://localhost:3001/auth-redirect?access_token=0e55c6fa93ae4e8cb11b35&action=change-email
note
If email confirmation is disabled in your App settings → Authentication view of Designer, it immediately updates the user's email and returns back the updated user data.
Example response
{
"user": {
"_id": "6235f78c0874df80013cae22",
"provider": "altogic",
"providerUserId": "6235f78c0874df80013caea2",
"email": "[email protected]",
"signUpAt": "2022-03-19T15:32:28.958Z",
"lastLoginAt": "2022-03-19T15:38:42.093Z",
"emailVerified": false,
"name": "Rooby"
},
"errors": null
}
Parameters
Here you can find parameters for the changeEmail
method.
# | Name | Data type | Required | Description |
---|---|---|---|---|
1 | currentPassword | String | Yes | The current password of the user. |
2 | newEmail | String | Yes | The new email address of the user. |
note
An active user session is required (e.g., user needs to be logged in) to call this method.