User authentication still in angularfire2

I have working authentication with angularfire2, I'm just wondering if there is another way to check if the user is verified after the user has recently logged in without logging into the server? The way I do it looks like this

isAuthenticated():boolean{ this.af.auth.subscribe(data => { if(data ){ // User is authenticated return true; } }); } 

Any help is appreciated

Change 1:

I decided to still use the source code to check if the user was recently logged in. That the proposed @cartant is good enough if you do not check the user when the application starts, because it can return null, as indicated in the official firebase docs. The way I used it here is that I have menu items that should only be displayed to authenticated users and using firebase.auth().currentUser will always return zero when the page loads.

+5
source share
1 answer

AngularFire2 is currently undergoing refactoring, and much of its authentication API will be removed in favor of using the Firebase Web API in conjunction with AngularFire2. See this issue for more details.

The watcher you used will remain in AngularFire2, and you can subscribe to it to receive notifications of changes in authentication status.

However, if everything that interests you determines if there is an authenticated user, there is a currentUser property in the Firebase web API that will tell you that:

 import * as firebase from "firebase"; ... console.log(firebase.auth().currentUser); 
+7
source

Source: https://habr.com/ru/post/1266750/


All Articles