shouheiyamauchi / react-passport-example

An example application for authentication using a Node.js back-end and React JS front-end
186 stars 62 forks source link

How to create modules #9

Open redimongo opened 5 years ago

redimongo commented 5 years ago

Ok, so I got it to work, but I am having a small issue I need the API url to be able to search collections etc.

how do I set that up?

I tried adding the following to api.js with no success

const express = require('express');
//const Pages = require('mongoose').model('Pages');

const router = new express.Router();

router.get('/dashboard', (req, res) => {
  res.status(200).json({
    message: "You're authorized to see this secret message.",
    // user values passed through from auth middleware
    user: req.user
  });
});

router.get('/pages', (req, res) => {
 /* Pages.find({}, function(err, docs) {
    if (!err){ 
        console.log(docs);
        process.exit();
    } else {throw err;}
  });
*/
  res.status(200).json({
    message: "You're authorized to see to edit pages.",
    // user values passed through from auth middleware
    user: req.user
  });
});

module.exports = router;