H
H
Haunted2013-12-20 09:27:58
Node.js
Haunted, 2013-12-20 09:27:58

Authentication via Passport (Node.js, Express) immediately after user registration

Friends,
You need to make a transition to another page immediately after registering a new user.
I took this code from an open project https://github.com/linnovate/mean/blob/master/app/...

exports.create = function(req, res) {
    var user = new User(req.body);
    var message = null;

    user.provider = 'local';
    user.save(function(err) {
        if (err) {
            switch(err.code){
                case 11000:
                case 11001:
                    message = 'Username already exists';
                    break;
                default: 
                    message = 'Please fill all the required fields';
            }

            return res.render('users/signup', {
                message: message,
                user: user
            });
        }
        req.logIn(user, function(err) {
            if (err) return next(err);
            return res.redirect('/');
        });
    });
};

I can’t understand why when I use this piece in my project, I get a TypeError, saying that there are no render and logIn methods (in theory, Passport should give it). The above method is made for a POST request.
Has anyone implemented something like this? Where should the render and logIn methods come from?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question