本文介绍了在angularfire中$ getAuth和$ onAuth之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了 $ getAuth()说:
$ b

而 $ onAuth()则表示:

所以你可以调用 $ getAth() 在你的代码中,如果你需要知道用户是否被认证。假设您想在计算时使用不同的价格进行验证:

  var productPrice = 50; 
$ scope.price = auth。$ getAuth()? 0.8 * productPrice:productPrice;

另一方面,如果您希望在 >用户通过身份验证,您可以使用 $ onAuth()。一个典型的例子是当用户登录/退出时将用户路由到不同的URL。


I was reading angularfire docs, and i found two similar services $getAuth and $onAuth given by firebase and both are written for checking user authentication. But i can't found any differences between both of them, can anybody describe them for me ?

and i also want to know that what is the good scenario to use each of these services. Thanks

link of official documentation

解决方案

As the documentation for $getAuth() says:

While for $onAuth() it says:

So you'd call $getAth() in your code if you need to know whether the user is authenticated. Say that you want to use a different price in a calculation when the user is authenticated:

var productPrice = 50;
$scope.price = auth.$getAuth() ? 0.8 * productPrice : productPrice;

If on the other hand you'd want to do something based on when the user is authenticated, you'd use $onAuth(). A typical example would be to route the user to a different URL when they sign-in/get signed out.

这篇关于在angularfire中$ getAuth和$ onAuth之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 05:56