使用角度和角度登录用户的正确方法是什么?表现? [英] What is the proper way to log in users using Angular & Express?

查看:82
本文介绍了使用角度和角度登录用户的正确方法是什么?表现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个简单的网站,我想让用户使用Facebook登录,然后根据用户是否登录,显示具有自定义项目的页面,即如果没有登录显示一些信息,但如果登录,它将显示其他信息基于他们的用户信息。



我正在使用护照js的Facebook模块,Express和Angular。我相信我有护照正确执行,但不知道1)我应该如何检查用户是否登录,以及2)根据用户状态显示视图的最佳做法,使用Angular&表现。我在这里看了一个例子,但不要以为这是我应该使用Angular( https ://github.com/jaredhanson/passport-facebook



谢谢!

解决方案

要完成@wpalahnuk答案,您必须创建一个服务或工厂来处理身份验证和一个httpInterceptor来拦截服务器发送的响应,以了解用户是否正在登录(检查对于Express部分,您必须使用真棒护照节点模块来处理服务器端身份验证。



您可以在这里查看所有详细信息: https://vickev.com/#!/article/authentication-in-single-page-applications-node-js-passportjs-angularjs



这篇文章真的很棒,Brad Green(AngularJS的Google工程总监)向我介绍了这篇文章。



希望它有帮助。



如果您想了解更多关于Angular安全性的内容,您只需要问问,我们很乐意为您提供帮助。


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!

解决方案

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.

这篇关于使用角度和角度登录用户的正确方法是什么?表现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆