Merge pull request #702 from simonbengtsson/before-save-login

Don't trigger beforeSave when logging in with a provider
This commit is contained in:
Fosco Marotto
2016-02-29 14:40:22 -08:00
2 changed files with 32 additions and 2 deletions

View File

@@ -1026,6 +1026,32 @@ describe('Parse.User testing', () => {
});
});
it("login with provider should not call beforeSave trigger", (done) => {
var provider = getMockFacebookProvider();
Parse.User._registerAuthenticationProvider(provider);
Parse.User._logInWith("facebook", {
success: function(model) {
Parse.User.logOut();
Parse.Cloud.beforeSave(Parse.User, function(req, res) {
res.error("Before save shouldn't be called on login");
});
Parse.User._logInWith("facebook", {
success: function(innerModel) {
Parse.Cloud._removeHook('Triggers', 'beforeSave', Parse.User.className);
done();
},
error: function(model, error) {
ok(undefined, error);
Parse.Cloud._removeHook('Triggers', 'beforeSave', Parse.User.className);
done();
}
});
}
});
});
it("link with provider", (done) => {
var provider = getMockFacebookProvider();
Parse.User._registerAuthenticationProvider(provider);

View File

@@ -67,12 +67,12 @@ RestWrite.prototype.execute = function() {
return this.handleInstallation();
}).then(() => {
return this.handleSession();
}).then(() => {
return this.validateAuthData();
}).then(() => {
return this.runBeforeTrigger();
}).then(() => {
return this.setRequiredFieldsIfNeeded();
}).then(() => {
return this.validateAuthData();
}).then(() => {
return this.transformUser();
}).then(() => {
@@ -136,6 +136,10 @@ RestWrite.prototype.validateSchema = function() {
// Runs any beforeSave triggers against this operation.
// Any change leads to our data being mutated.
RestWrite.prototype.runBeforeTrigger = function() {
if (this.response) {
return;
}
// Avoid doing any setup for triggers if there is no 'beforeSave' trigger for this class.
if (!triggers.triggerExists(this.className, triggers.Types.beforeSave, this.config.applicationId)) {
return Promise.resolve();