【发布时间】:2016-10-16 09:33:18
【问题描述】:
这是我第一次使用 AngularJs,不确定我的身份验证是否正确处理。
我希望$firebaseAuth() 即使我刷新应用程序也会保持身份验证状态。但是每次刷新app,$firebaseAuth()不会重新认证用户,需要重新登录。
我通读了文档并在源代码中搜索,但找不到允许我配置会话持久性的功能。只接受email 和password 2 个参数。
版本:
angularjs v1.4.10
angularfire v2.0.1
火力基地 v3.0.3
我的authenticationServicelitcoffee 脚本
app.factory "authenticationService", [
"$firebaseAuth"
"$location"
"$rootScope"
($firebaseAuth, $location, $rootScope) ->
login: (email, password, redirectUrl = "/") ->
$rootScope.authObj.$signInWithEmailAndPassword(email, password)
.then(
(firebaseUser) ->
console.log firebaseUser
$rootScope.firebaseUser = firebaseUser
return true
(error) ->
$rootScope.firebaseUser = null
console.log error
alert error.message
return false
)
logout: (redirectUrl = "/login") ->
$rootScope.authObj.$signOut()
$location.path redirectUrl
isLogged: () ->
if $rootScope.authObj.$getAuth()
return true
else
return false
]
我在调用authenticationService.isLogged() 的控制器上检查用户身份验证状态,如果用户未登录,它将重定向到登录页面。
我想要实现的只是一个简单的身份验证,用户即使刷新也会保持身份验证状态。
如果我的方向错误,请纠正我。任何帮助将不胜感激。
【问题讨论】:
标签: angularjs firebase angularfire