0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Removed dupe use of labs.members & leftover file

- Meant to cleanup the old api/canary/members earlier, removed now as it's unused
- Also removed all the duplicate references to labs.members in various places
This commit is contained in:
Hannah Wolfe 2020-04-30 19:33:09 +01:00
parent 0cba02b370
commit 5365522cf5
3 changed files with 23 additions and 62 deletions

View file

@ -3,6 +3,25 @@ const labsService = require('../labs');
const membersService = require('./index');
const urlUtils = require('../../lib/url-utils');
// @TODO: This piece of middleware actually belongs to the frontend, not to the member app
// Need to figure a way to separate these things (e.g. frontend actually talks to members API)
const loadMemberSession = async function (req, res, next) {
if (!labsService.isSet('members')) {
req.member = null;
return next();
}
try {
const member = await membersService.ssr.getMemberDataFromSession(req, res);
Object.assign(req, {member});
res.locals.member = req.member;
next();
} catch (err) {
common.logging.warn(err.message);
Object.assign(req, {member: null});
next();
}
};
const getIdentityToken = async function (req, res) {
try {
const token = await membersService.ssr.getIdentityTokenForMemberFromSession(req, res);
@ -27,27 +46,7 @@ const deleteSession = async function (req, res) {
}
};
const loadMemberSession = async function (req, res, next) {
if (!labsService.isSet('members')) {
req.member = null;
return next();
}
try {
const member = await membersService.ssr.getMemberDataFromSession(req, res);
Object.assign(req, {member});
res.locals.member = req.member;
next();
} catch (err) {
common.logging.warn(err.message);
Object.assign(req, {member: null});
next();
}
};
const getMemberData = async function (req, res) {
if (!labsService.isSet('members')) {
res.json(null);
}
try {
const member = await membersService.ssr.getMemberDataFromSession(req, res);
if (member) {
@ -71,9 +70,6 @@ const getMemberData = async function (req, res) {
};
const createSessionFromMagicLink = async function (req, res, next) {
if (!labsService.isSet('members')) {
return next();
}
if (!req.url.includes('token=')) {
return next();
}
@ -100,7 +96,6 @@ const createSessionFromMagicLink = async function (req, res, next) {
}
};
// @TODO only load this stuff if members is enabled
// Set req.member & res.locals.member if a cookie is set
module.exports = {
loadMemberSession,

View file

@ -1,34 +0,0 @@
const {URL} = require('url');
const debug = require('ghost-ignition').debug('web:canary:members:app');
const express = require('../../../../../shared/express');
const cors = require('cors');
const membersService = require('../../../../services/members');
const urlUtils = require('../../../../lib/url-utils');
const labs = require('../../../shared/middlewares/labs');
const shared = require('../../../shared');
module.exports = function setupMembersApiApp() {
debug('Members API canary setup start');
const apiApp = express();
// Entire app is behind labs flag
apiApp.use(labs.members);
// Support CORS for requests from the frontend
const siteUrl = new URL(urlUtils.getSiteUrl());
apiApp.use(cors(siteUrl.origin));
// NOTE: this is wrapped in a function to ensure we always go via the getter
apiApp.post('/send-magic-link', (req, res, next) => membersService.api.middleware.sendMagicLink(req, res, next));
apiApp.post('/create-stripe-checkout-session', (req, res, next) => membersService.api.middleware.createCheckoutSession(req, res, next));
apiApp.post('/create-stripe-setup-session', (req, res, next) => membersService.api.middleware.createCheckoutSetupSession(req, res, next));
apiApp.put('/subscriptions/:id', (req, res, next) => membersService.api.middleware.updateSubscription(req, res, next));
// API error handling
apiApp.use(shared.middlewares.errorHandler.resourceNotFound);
apiApp.use(shared.middlewares.errorHandler.handleJSONResponseV2);
debug('Members API canary setup end');
return apiApp;
};

View file

@ -24,12 +24,12 @@ module.exports = function setupMembersApp() {
// Routing
// Webhooks
membersApp.post('/webhooks/stripe', shared.middlewares.labs.members, middleware.stripeWebhooks);
membersApp.post('/webhooks/stripe', middleware.stripeWebhooks);
// Initializes members specific routes as well as assigns members specific data to the req/res objects
membersApp.get('/api/member', shared.middlewares.labs.members, middleware.getMemberData);
membersApp.get('/api/session', shared.middlewares.labs.members, middleware.getIdentityToken);
membersApp.delete('/api/session', shared.middlewares.labs.members, middleware.deleteSession);
membersApp.get('/api/member', middleware.getMemberData);
membersApp.get('/api/session', middleware.getIdentityToken);
membersApp.delete('/api/session', middleware.deleteSession);
// NOTE: this is wrapped in a function to ensure we always go via the getter
membersApp.post('/api/send-magic-link', (req, res, next) => membersService.api.middleware.sendMagicLink(req, res, next));