From 683912417e6677f0b7dae4b8327318ace0825490 Mon Sep 17 00:00:00 2001 From: Robin Orheden Date: Thu, 14 Jul 2016 23:32:39 +0200 Subject: [PATCH] fix so that login handlers run after registration --- lib/helpers/login-with-oauth-provider.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/helpers/login-with-oauth-provider.js b/lib/helpers/login-with-oauth-provider.js index a6cdd7fd..71366864 100644 --- a/lib/helpers/login-with-oauth-provider.js +++ b/lib/helpers/login-with-oauth-provider.js @@ -39,7 +39,7 @@ module.exports = function loginWithOAuthProvider(options, req, res) { }); } - function continueWithHandlers(preHandler, postHandler) { + function continueWithHandlers(preHandler, postHandler, onCompleted) { preHandler(options, req, res, function (err) { if (err) { return oauth.errorResponder(req, res, err); @@ -51,20 +51,22 @@ module.exports = function loginWithOAuthProvider(options, req, res) { return oauth.errorResponder(req, res, err); } - continueWithTokenExchange(); + onCompleted(); }); } - continueWithTokenExchange(); + onCompleted(); }); } if (preRegistrationHandler && providerAccountResult.created) { - return continueWithHandlers(preRegistrationHandler, postRegistrationHandler); + return continueWithHandlers(preRegistrationHandler, postRegistrationHandler, function () { + continueWithHandlers(preLoginHandler, postLoginHandler, continueWithTokenExchange); + }); } - if (preLoginHandler && !providerAccountResult.created) { - return continueWithHandlers(preLoginHandler, postLoginHandler); + if (preLoginHandler) { + return continueWithHandlers(preLoginHandler, postLoginHandler, continueWithTokenExchange); } continueWithTokenExchange();