mirror of
https://github.com/wassname/talk.git
synced 2026-07-05 04:14:04 +08:00
fixes based on feedback
This commit is contained in:
+5
-5
@@ -46,16 +46,16 @@ const decorateContextPlugins = (context, contextPlugins) => {
|
||||
* Stores the request context.
|
||||
*/
|
||||
class Context {
|
||||
constructor(parent) {
|
||||
constructor(ctx) {
|
||||
// Generate a new context id for the request if the parent doesn't provide
|
||||
// one.
|
||||
this.id = parent.id || uuid.v4();
|
||||
this.id = ctx.id || uuid.v4();
|
||||
|
||||
// Attach a logger or create one.
|
||||
this.log = parent.log || createLogger('context', this.id);
|
||||
this.log = ctx.log || createLogger('context', this.id);
|
||||
|
||||
// Load the current logged in user to `user`, otherwise this will be null.
|
||||
this.user = get(parent, 'user');
|
||||
this.user = get(ctx, 'user');
|
||||
|
||||
// Attach the connectors.
|
||||
this.connectors = connectors;
|
||||
@@ -73,7 +73,7 @@ class Context {
|
||||
this.pubsub = getBroker();
|
||||
|
||||
// Bind the parent context.
|
||||
this.parent = parent;
|
||||
this.parent = ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { passport } = require('../services/passport');
|
||||
const Context = require('../graph/context');
|
||||
const debug = require('debug')('talk:middleware:authentication');
|
||||
|
||||
const authentication = (req, res, next) =>
|
||||
@@ -22,6 +23,9 @@ const authentication = (req, res, next) =>
|
||||
debug('user was not on request');
|
||||
}
|
||||
|
||||
// Attach a new context to the request.
|
||||
req.context = new Context(req);
|
||||
|
||||
next();
|
||||
}
|
||||
)(req, res, next);
|
||||
|
||||
@@ -4,9 +4,12 @@ module.exports = router => {
|
||||
* for authorization.
|
||||
*/
|
||||
router.get('/api/v1/auth/facebook', (req, res, next) => {
|
||||
const { connectors: { services: { Passport } } } = req.context;
|
||||
const {
|
||||
connectors: { services: { Passport: { passport } } },
|
||||
} = req.context;
|
||||
console.log(req.context.connectors.services);
|
||||
|
||||
return Passport.authenticate('facebook', {
|
||||
return passport.authenticate('facebook', {
|
||||
display: 'popup',
|
||||
authType: 'rerequest',
|
||||
scope: ['public_profile'],
|
||||
@@ -18,11 +21,14 @@ module.exports = router => {
|
||||
* send back the user credentials upon successful login.
|
||||
*/
|
||||
router.get('/api/v1/auth/facebook/callback', (req, res, next) => {
|
||||
const { connectors: { services: { Passport } } } = req.context;
|
||||
const { HandleAuthPopupCallback } = Passport;
|
||||
const {
|
||||
connectors: {
|
||||
services: { Passport: { passport, HandleAuthPopupCallback } },
|
||||
},
|
||||
} = req.context;
|
||||
|
||||
// Perform the facebook login flow and pass the data back through the opener.
|
||||
Passport.authenticate(
|
||||
passport.authenticate(
|
||||
'facebook',
|
||||
{ session: false },
|
||||
HandleAuthPopupCallback(req, res, next)
|
||||
|
||||
@@ -11,7 +11,6 @@ const plugins = require('../services/plugins');
|
||||
const staticTemplate = require('../middleware/staticTemplate');
|
||||
const staticMiddleware = require('express-static-gzip');
|
||||
const { DISABLE_STATIC_SERVER } = require('../config');
|
||||
const Context = require('../graph/context');
|
||||
const { passport } = require('../services/passport');
|
||||
const { MOUNT_PATH } = require('../url');
|
||||
|
||||
@@ -66,12 +65,6 @@ if (!DISABLE_STATIC_SERVER) {
|
||||
// Add the i18n middleware to all routes.
|
||||
router.use(i18n);
|
||||
|
||||
// Bind a new context to the request.
|
||||
router.use((req, res, next) => {
|
||||
req.context = new Context(req);
|
||||
next();
|
||||
});
|
||||
|
||||
// Compress all API responses if appropriate.
|
||||
router.use(compression());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user