0

i tried to find a solution everywhere and had no luck.

I have the Route on my nodejs api app like:

app.post('/login', passport.authenticate('local-login', {
    successRedirect: '/profile',
    failureRedirect: '/login',
    failureFlash: true
}));

Then, on my passport strategy like this:

passport.use('local-login', new LocalStrategy({
    usernameField: 'email',
    passwordField: 'password',
    passReqToCallback: true
},
    function (req, email, password, done) {
        User.findOne({ 'local.email': email }, function (err, user) {
            if (err) {
                return done(err);
            }
            if (!user) {
                return done(null, false, req.flash('LoginMessage', 'No User Found!'));
            }
            if (user.local.password != password) {
                return done(null, false, req.flash('LoginMessage', 'Wrong Password!'));
            } else {
                return done(null, user);
            }
        })
    }
));

What i need, is to receive the message as a json return on my route, so i can access it with external apps using Angularjs or anything else. so the output would be something like:

{
"message": "User Not Found!"
}

How can i solve this problem?

William Xavier
  • 478
  • 3
  • 20

1 Answers1

0

To initialize message as an angular variable you can do this in your view-file (if you're using ejs):

ng-init="message = '<%= message %>'"

further, u can work with this variable

Yrysbek Tilekbekov
  • 2,685
  • 11
  • 17