Posts

Showing posts with the label firebase-authentication

Angular / Firestore - What's the best way to check the User ID in multiple components?

Angular / Firestore - What's the best way to check the User ID in multiple components? I have an 'authservice.ts' file where I try to manage user auth style things. However, in each of my components, I'm always subscribing to the user to get the user ID. The user ID is then used inside my Firestore functions to query data where the user ID is referenced inside collection and document paths. Is there a more 'fluent' way of achieving the same thing? Or is this approach actually suitable? Below are the examples of the auth service and a component file that references the auth service. auth-service.ts ... user: Observable<firebase.User>; ... constructor() { this.user = afAuth.authState; } Any One Of My Components.ts ... private _subscription: Subscription; ... ngOnInit() { this.subscribeToUser(); } subscribeToUser() { this._subscription = this.authService.user.subscribe(user => { if (user) { this.userID = user.uid; th...

Javascript execution order when pulling Firebase data

Javascript execution order when pulling Firebase data After I authenticate to Firebase with Google auth, I get this console.log output and the JavaScript seems to bounce around in execution order. Here's my console output and the javascript code. console.log Why does "controller is: Pellet_Pirate_1" display at the log end rather than at the beginning where the code executes to pull this value from Firebase? My "GLOBAL CONTROLLER" and other logs of the contr global variable should be valued as well... I am trying to use contr as a global variable and it is defined at the top of my script tag contr contr Any help would be greatly appreciated... I've banged my head on this one for many hours now! console.log <script type="text/javascript"> var contr = undefined; function PelletPirate() { this.userPic = document.getElementById('user-pic'); this.userName = document.getElementById('user-name'); this.signInButton = d...