Skip to content

Changing user's email: keep using old email before verification new one #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/ParseUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,33 @@ class ParseUser extends ParseObject {
return controller.logIn(this, loginOptions);
}

/**
* Requires email change for user. It save new email into field
* <code>emailNew</code>.
*
* <p>Calls options.success or options.error on completion.</p>
*

* @param {string} email
* @param {Object} options
* @return {Promise} A promise that is fulfilled when
* the operation is complete.
*/
requestEmailChange(email: string, options: FullOptions): Promise {
options = options || {};

var requestOptions = {};
if (options.hasOwnProperty('useMasterKey')) {
requestOptions.useMasterKey = options.useMasterKey;
}
if (options.hasOwnProperty('installationId')) {
requestOptions.installationId = options.installationId;
}

var controller = CoreManager.getUserController();
return controller.requestEmailChange(this, email, requestOptions);
}

/**
* Wrap the default save behavior with functionality to save to local
* storage if this is current user.
Expand Down Expand Up @@ -1061,6 +1088,28 @@ const DefaultController = {
}
return user;
});
},

requestEmailChange(user: ParseUser, email: string, options: RequestOptions) {
var token = user.getSessionToken();
if (!token) {
return Promise.reject(
new ParseError(
ParseError.SESSION_MISSING,
'Cannot upgrade a user with no session token'
)
);
}

options.sessionToken = token;

var RESTController = CoreManager.getRESTController();
return RESTController.request(
'POST',
'requestEmailChange',
{ email: email },
options
);
}
};

Expand Down