Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way to log in users using Angular & Express?

I'm building a simple web site where I'd like to let users log in using Facebook, and then show a page with customized items based on whether or not they're logged in. ie if not logged it, it shows some info, but if logged in, it shows other info based on their user information.

I'm using the passportjs Facebook module, Express, and Angular. I believe I have passport implemented correctly, but don't know 1) how I should be checking if a user is logged in, and 2) best practice for showing views based on the user state using Angular & Express. I've looked at an example here, but don't think this is what I should be doing using Angular (https://github.com/jaredhanson/passport-facebook)

Thanks!

like image 562
manihiki Avatar asked Sep 14 '13 18:09

manihiki


People also ask

What is correct for authentication and authorization in Angular?

Angular Interview Q & A series Authentication is very important process in the system with respect to security. Authorization is the process of giving permission to the user to access certain resource in the system. Only the authenticated user can be authorised to access a resource.

How is Angular authentication done?

When your users need to log in, your Angular application triggers an authentication event, which it handles by redirecting them to a customizable Auth0 login page. Once your users log in successfully, Auth0 redirects them back to your Angular application, returning tokens with their authentication and user information.

What is SSO in Angular?

Angular Single Sign-On SSO. This solution allows you to setup Single Sign-On into . It allows setting up JWT SSO.


1 Answers

To complete the @wpalahnuk answer you have to create a service or factory to deal the authentication and an httpInterceptor to intercept the response send by the server for know if the user is log or not (checking the staus code 401).

For the Express part you have to use the awesome passport node module to deal the server side authentication.

You have all the details here : https://vickev.com/#!/article/authentication-in-single-page-applications-node-js-passportjs-angularjs

This article is really great, Brad Green (Engineering Director at Google for AngularJS) adivse me this post.

Hope it Helps.

If you want to know more things about security in Angular you have just to ask and i'll we be really happy to help you.

like image 54
Thomas Pons Avatar answered Sep 28 '22 04:09

Thomas Pons