Guest User

Untitled

a guest
Jul 16th, 2018
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. user with id xxx serialized
  2. email: ...
  3. password: ...
  4. isAuthenticated: true
  5. Session {
  6. path: '/',
  7. _expires: null,
  8. originalMaxAge: null,
  9. httpOnly: true },
  10. passport: {user: xxx } }
  11.  
  12. app.use(session({
  13. secret: 'test',
  14. saveUninitialized: false,
  15. resave: true
  16. }));
  17. app.use(passport.initialize());
  18. app.use(passport.session());
  19.  
  20. router.get('/',function(req, res){
  21. console.log(req.user);
  22. console.log(req.session);
  23. });
  24.  
  25. router.post('/login',passport.authenticate('local'), function(req,res)
  26. {
  27. console.log(req.user);
  28. console.log(req.isAuthenticated());
  29. console.log(req.session);
  30. });
  31.  
  32. passport.serializeUser(function(user, done) {
  33. console.log("user with id " + user._id + " serialized");
  34. done(null, user._id);
  35. });
  36.  
  37. passport.deserializeUser(function(id, done) {
  38. console.log("deserializing user with id " + id + " ");
  39. User.findById(id, function(err, user) {
  40. done(err, user);
  41. });
  42. });
  43.  
  44. componentDidMount(){
  45. var current_user = "";
  46. fetch("http://localhost:3001/users/", {
  47. method: "get",
  48. headers: {
  49. 'Accept':'application/json',
  50. 'Content-Type': 'application/json'
  51. }
  52. })
  53. .then( (response)=> response.json())
  54. .then( (response)=> {
  55. if(response.user!==current_user){
  56. current_user = response.user;
  57. this.setState({
  58. user: current_user
  59. }), ()=> console.log(response);
  60. }
  61. })
  62. }
Add Comment
Please, Sign In to add comment