gpt4 book ai didi

angularjs - angularfire $waitForSignIn() 用法?

转载 作者:行者123 更新时间:2023-12-02 04:40:14 24 4
gpt4 key购买 nike

我想弄清楚 $waitForSignIn()

的用法是什么

文档说:

$waitForSignIn() which returns a promise fulfilled with the current authentication state. This is useful when you want to grab the authentication state before the route is rendered

但这将如何运作?

他们说你应该实现如下(来自:link):

app.config(["$stateProvider", function ($stateProvider) {
$stateProvider
.state("home", {
// the rest is the same for ui-router and ngRoute...
controller: "HomeCtrl",
templateUrl: "views/home.html",
resolve: {
// controller will not be loaded until $waitForSignIn resolves
// Auth refers to our $firebaseAuth wrapper in the example above
"currentAuth": ["Auth", function(Auth) {
// $waitForSignIn returns a promise so the resolve waits for it to complete
return Auth.$waitForSignIn();
}]
}
})
.state("account", {
// the rest is the same for ui-router and ngRoute...
controller: "AccountCtrl",
templateUrl: "views/account.html",
resolve: {
// controller will not be loaded until $requireSignIn resolves
// Auth refers to our $firebaseAuth wrapper in the example above
"currentAuth": ["Auth", function(Auth) {
// $requireSignIn returns a promise so the resolve waits for it to complete
// If the promise is rejected, it will throw a $stateChangeError (see above)
return Auth.$requireSignIn();
}]
}
});
}]);

所以您希望在用户登录时加载 HomeCtrl 吗?但是当没有用户登录时,它会在 null 上加载 currentAuth,

然后我尝试在 currentAuth 上放置一个观察者,当用户登录时没有变化。但是没有触发登录或退出的事件

接下来我想它只会在您尝试登录时等待(例如通过弹出窗口)。所以我启动了弹出窗口,然后直接切换到主页,但随后我从 currentAuth 得到了一个 null,如果我刷新,我得到了我的用户数据。

那有什么意义呢?只是为了在用户可用时解决用户问题?

最佳答案

您应该期望您的 HomeCtrl 知道用户是否已登录,如果用户未登录,您的帐户路由将限制访问。

关于angularjs - angularfire $waitForSignIn() 用法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38170899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com