Tuesday, 11 April 2017

How to give user state from node to angular?

I am using Nodejs with AngularJS. And I am trying to make an authentication system with Passport.

The facebook authentication strategy works. When I click on the link in login.html it creates a new entry to my MongoDB database and it redirects me to the profile page.

But how can I give back the user state to the AngularJs app? (to all views)

Route for facebook authentication

// route for facebook authentication and login
    app.get('/auth/facebook', passport.authenticate('facebook', { scope : 'email' }));

    // handle the callback after facebook has authenticated the user
    app.get('/auth/facebook/callback',
        passport.authenticate('facebook', {
            successRedirect : '/#!/profile',
            failureRedirect : '/failure'
        }));

Login.html

<a href="/auth/facebook" target="_self" class="btn btn-primary"><span class="fa fa-facebook"></span> Facebook</a>



via DowinskiField

No comments:

Post a Comment