Added membersStripeConnect controller auth method

no-issue

In order to issue a redirect we need access to the "raw" req/res
objects, which is why we must return the function which gets access to
them.

The members service is used to create the auth url and to update the
users session.
This commit is contained in:
Fabien O'Carroll 2020-05-28 12:40:51 +02:00 committed by Fabien 'egg' O'Carroll
parent 5b058d6d5b
commit fc0e97593b
3 changed files with 24 additions and 0 deletions

View File

@ -71,6 +71,10 @@ module.exports = {
return shared.pipeline(require('./settings'), localUtils);
},
get membersStripeConnect() {
return shared.pipeline(require('./membersStripeConnect'), localUtils);
},
get members() {
return shared.pipeline(require('./members'), localUtils);
},

View File

@ -0,0 +1,18 @@
const membersService = require('../../services/members');
module.exports = {
docName: 'members_stripe_connect',
auth: {
permissions: true,
query(frame) {
// This is something you have to do if you want to use the "framework" with access to the raw req/res
frame.response = async function (req, res) {
function setSessionProp(prop, val) {
req.session[prop] = val;
}
const stripeConnectAuthURL = await membersService.stripeConnect.getStripeConnectOAuthUrl(setSessionProp);
return res.redirect(stripeConnectAuthURL);
};
}
}
};

View File

@ -97,6 +97,8 @@ module.exports = function apiRoutes() {
http(apiCanary.members.importCSV)
);
router.get('/members/stripe_connect', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.membersStripeConnect.auth));
router.get('/members/:id', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.members.read));
router.put('/members/:id', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.members.edit));
router.del('/members/:id', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.members.destroy));