I have a react front-end hitting an express server that is only use for API calls. I'm using passport for authentication and I'm having some issues. I have a strategy set up for Facebook. I am able to login using Facebook, the serialize method is called, the user is added to the DB, and I'm able to see the req.user object in the strategy callback method but, I am not able to get the req.user object after this point. Any suggestions?
App.js
let express = require('express');
let router = express.Router();
let passport = require('passport');
router.get('/login/facebook', passport.authenticate('facebook', {scope: ["email"]}));
router.get('/facebook/return',
passport.authenticate('facebook', { failureRedirect: '/' }),
(req, res) => {
res.redirect('http://localhost:3000');
});
router.get('/logout',
passport.authenticate('facebook', { failureRedirect: '/' }),
(req, res) => {
req.logout();
res.redirect('http://localhost:3000');
});
module.exports = router;
Auth.js
let express = require('express');
let router = express.Router();
let passport = require('passport');
router.get('/login/facebook', passport.authenticate('facebook', {scope: ["email"]}));
router.get('/facebook/return',
passport.authenticate('facebook', { failureRedirect: '/' }),
(req, res) => {
res.redirect('http://localhost:3000');
});
router.get('/logout',
passport.authenticate('facebook', { failureRedirect: '/' }),
(req, res) => {
req.logout();
res.redirect('http://localhost:3000');
});
module.exports = router;
Species.js
let express = require("express");
let router = express.Router();
let Species = require("../models/species").Species;
router.get('/',
(req, res, next) => {
console.log(req.user);
Species.find({}).exec((err, species) => {
if(err) return next(err);
res.json(species);
});
});
module.exports = router;