Angularfire Auth 会话持久性
Angularfire Auth session persistence
这是我第一次使用 AngularJs,不确定我的身份验证处理是否正确。
我希望 $firebaseAuth()
即使我刷新应用程序也会保持身份验证状态。但是我每次刷新应用程序,$firebaseAuth()
不会重新验证用户,我需要重新登录。
我通读了文档并在源代码中搜索,但找不到允许我配置会话持久性的函数。仅接受 2 个参数 email
和 password
。
版本:
angularjs v1.4.10
angularfire v2.0.1
firebase v3.0.3
我的 authenticationService
litcoffee 脚本
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()
的控制器上检查用户身份验证状态,如果用户未登录,它将重定向到登录页面。
我想要实现的只是一个简单的认证,用户即使刷新也会保持认证状态。
如果我的方向错误,请纠正我。任何帮助将不胜感激。
其实是我的错。
Firebase 和 AngularFire 默认保持身份验证会话持久性。
我做错的是在页面加载时立即检查身份验证状态。目前 AngularFire 还没有启动,需要一些时间来重新验证应用程序。
因此,$firebaseAuth.$onAuthStateChanged 会很有帮助。
当您的页面加载时收听它。事件触发后,它会通知您用户是否已通过身份验证。
这是我第一次使用 AngularJs,不确定我的身份验证处理是否正确。
我希望 $firebaseAuth()
即使我刷新应用程序也会保持身份验证状态。但是我每次刷新应用程序,$firebaseAuth()
不会重新验证用户,我需要重新登录。
我通读了文档并在源代码中搜索,但找不到允许我配置会话持久性的函数。仅接受 2 个参数 email
和 password
。
版本:
angularjs v1.4.10
angularfire v2.0.1
firebase v3.0.3
我的 authenticationService
litcoffee 脚本
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()
的控制器上检查用户身份验证状态,如果用户未登录,它将重定向到登录页面。
我想要实现的只是一个简单的认证,用户即使刷新也会保持认证状态。
如果我的方向错误,请纠正我。任何帮助将不胜感激。
其实是我的错。 Firebase 和 AngularFire 默认保持身份验证会话持久性。 我做错的是在页面加载时立即检查身份验证状态。目前 AngularFire 还没有启动,需要一些时间来重新验证应用程序。
因此,$firebaseAuth.$onAuthStateChanged 会很有帮助。 当您的页面加载时收听它。事件触发后,它会通知您用户是否已通过身份验证。