I examined a number of resources, including this , this, and this , but I could not achieve the desired result.
All I'm trying to do is authenticate the user (using firebase) and then after authentication load my profile and save it in the userProfile
variable before loading the next page. Dashboard:
My Login Service:
public signinUser(user: User) { this.af.auth.login({ email: user.email, password: user.password }, { provider: AuthProviders.Password, method: AuthMethods.Password } ) .then( success => { console.log('Authenticated'); this.getProfile().subscribe( // PROBLEM is here profile => { console.log(profile); console.log('Profile Loaded'); this.router.navigate(['/dashboard']); } ) } ) .catch(function (error) { ... console.log('ERROR SIGNING USER IN'); }
My getProfile()
method:
public getProfile(): Observable<any> { return this.af.database.object('/profiles/' + this.user.uid) .flatMap( profile => { console.log('inside success'); console.log(profile); this.userProfile = <User>profile; console.log('getProfile has completed'); return profile; }, error => { console.log(error) });
Here is what the log part looks like:
Authenticated auth.service.ts:104 ERROR SIGNING USER IN auth.service.ts:105 TypeError: Cannot read property 'subscribe' of undefined at auth.service.ts:91 at ZoneDelegate.invoke (zone.js:232) at Object.onInvoke (ng_zone.js:238) at ZoneDelegate.invoke (zone.js:231) at Zone.run (zone.js:114) at zone.js:502 at ZoneDelegate.invokeTask (zone.js:265) at Object.onInvokeTask (ng_zone.js:229) at ZoneDelegate.invokeTask (zone.js:264) at Zone.runTask (zone.js:154) auth.service.ts:106 Cannot read property 'subscribe' of undefined auth.service.ts:184 inside success auth.service.ts:185 Object {confirmPassword: "123123", email: " aaa@gmail.com2 ", github: "aaa" name: "a", password: "123123"…} auth.service.ts:188 getProfile has completed() auth.service.ts:185
I see that the methods individually work as intended. The user is authenticated and the profile is loaded (displayed in the log). The problem is the subscription event for reasons I don't know.
source share