From 57210705f4d3dcf6c44e9dc4022b81f3024ddb96 Mon Sep 17 00:00:00 2001 From: Gerwin Brunner Date: Thu, 24 Aug 2017 18:18:44 +0200 Subject: [PATCH] added onUserUpdate hook --- packages/accounts-base/accounts_server.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/accounts-base/accounts_server.js b/packages/accounts-base/accounts_server.js index ef07ad0cb2..ddf91c089b 100644 --- a/packages/accounts-base/accounts_server.js +++ b/packages/accounts-base/accounts_server.js @@ -119,6 +119,22 @@ export class AccountsServer extends AccountsCommon { this._onCreateUserHook = func; } + + + /** + * @summary Customize oauth user profile updates + * @locus Server + * @param {Function} func Called whenever a user is logged in via oauth. Return the profile object to be merged, or throw an `Error` to abort the creation. + */ + onUpdateUser(func) { + if (this._onUpdateUserHook) { + throw new Error("Can only call onUpdateUser once"); + } + + this._onUpdateUserHook = func; + } + + }; var Ap = AccountsServer.prototype; @@ -1440,8 +1456,15 @@ Ap.updateOrCreateUserFromExternalService = function ( setAttrs["services." + serviceName + "." + key] = value; }); + var opts = {}; + + if (this._onUpdateUserHook) { + opts = this._onUpdateUserHook(options, user); + } + // XXX Maybe we should re-use the selector above and notice if the update // touches nothing? + setAttrs = _.extend({}, setAttrs, opts); this.users.update(user._id, { $set: setAttrs });