Answer the question
In order to leave comments, you need to log in
Problems when working with services on Angular 2. How to fix?
Hello, I have a question about Angular 2
I'm dealing with authorization for FireBase, but there was one problem
https://pastebin.com/6Ei3K9N6
When calling the checkAuthorization() function, the output is:
'reality: true'
'service -> auth = undefined'
I can't understand why this is happening, because in both cases I refer to the this.isAuthorized variable
PS: I just need that when this function is called from the component, the value of the isAuthorized variable changes and returns from the function so that I can then use this value in the component.
Answer the question
In order to leave comments, you need to log in
Initialize it on declaration ( ...boolean = false) and instead of undefined it will be false )
At the time of console.log('service -> auth =', this.isAuthorized) your listener (user) => { if (user) .. .doesn't fire yet because afAuth: AngularFireAuth hasn't yet triggered onAuthStateChanged.
https://firebase.google.com/docs/reference/js/fire...
Put console.log('service -> auth =', this.isAuthorized) in your callback at the very end and see what happens.
PS: I've been familiar with Angular for 1 week, I didn't encounter authorization for FireBase at all, I just read the doc, don't kick it if anything)
PS : logically, as I understand it, you need to subscribe to a state in which to store isAuthorized, from the value of which the logic of the work of other components will be repelled (render a profile button or user login/registration buttons, access to some functionality, etc.)
UPD: I forgot the link - I didn’t forget, fatigue affects)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question