Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- user with id xxx serialized
- email: ...
- password: ...
- isAuthenticated: true
- Session {
- path: '/',
- _expires: null,
- originalMaxAge: null,
- httpOnly: true },
- passport: {user: xxx } }
- app.use(session({
- secret: 'test',
- saveUninitialized: false,
- resave: true
- }));
- app.use(passport.initialize());
- app.use(passport.session());
- router.get('/',function(req, res){
- console.log(req.user);
- console.log(req.session);
- });
- router.post('/login',passport.authenticate('local'), function(req,res)
- {
- console.log(req.user);
- console.log(req.isAuthenticated());
- console.log(req.session);
- });
- passport.serializeUser(function(user, done) {
- console.log("user with id " + user._id + " serialized");
- done(null, user._id);
- });
- passport.deserializeUser(function(id, done) {
- console.log("deserializing user with id " + id + " ");
- User.findById(id, function(err, user) {
- done(err, user);
- });
- });
- componentDidMount(){
- var current_user = "";
- fetch("http://localhost:3001/users/", {
- method: "get",
- headers: {
- 'Accept':'application/json',
- 'Content-Type': 'application/json'
- }
- })
- .then( (response)=> response.json())
- .then( (response)=> {
- if(response.user!==current_user){
- current_user = response.user;
- this.setState({
- user: current_user
- }), ()=> console.log(response);
- }
- })
- }
Add Comment
Please, Sign In to add comment