how to send json as a response after passport authenticationin node.js

后端 未结 6 471
日久生厌
日久生厌 2021-01-05 06:16

I am trying this git example.

Which works well when I integrated it with my project, but what I want to achieve is to send json as a response to the client/request,

6条回答
  •  隐瞒了意图╮
    2021-01-05 06:49

    here I modified my code to send json as a response

    // process the signup form
    app.post('/signup', passport.authenticate('local-signup', {
        successRedirect : '/successjson', // redirect to the secure profile section
        failureRedirect : '/failurejson', // redirect back to the signup page if there is an error
        failureFlash : true // allow flash messages
    }));
    
    app.get('/successjson', function(req, res) {
        res.sendfile('public/index.htm');
    });
    
    app.get('/failurejson', function(req, res) {
        res.json({ message: 'hello' });
    });
    

提交回复
热议问题