Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot read property 'firebaseApp' of undefined using Ngrx

Error When Assigned Full Firebase Authentication Return

I am logging into my application and the moment the login is successfully done I call an action to change the state of my application receiving the data of the authenticated user of Firebase Authentication.

When I try to pass the entire object to user the following error occurs:

ERROR TypeError: Cannot read property 'firebaseApp' of undefined
    at Object.get [as app] (http://localhost:4200/vendor.js:165544:31)
    at http://localhost:4200/vendor.js:193044:9
    at Array.forEach (<anonymous>)
    at deepFreeze (http://localhost:4200/vendor.js:193041:33)

This occurs when I start the constructor(user: any) in my action with the whole object returned from the Firebase server.

But if I access other properties of the object with: (id, displayName, email) this error does not occur, it only occurs when I try to assign the entire object returned.

auth.effets.ts

@Effect()
loginAction$: Observable<Action> = this._actions$
    .ofType(authActions.ActionsTypes.LOGIN_REQUESTED).pipe(
        map((action: authActions.LoginCompletedAction) => action.payload),
        switchMap(payload => this._authService.loginWithEmailAndPassword(payload.user).pipe(
            map((res) => (new authActions.LoginCompletedAction(new authActions.AuthUserPayload(res.user)))),
            catchError((error) => of(new authActions.AuthErrorAction({ error: error })))
        ))
    );

res.user -> ERROR OCCURS (return of Firebase when called the method signInWithEmailAndPassword (email, password))

res.user.displayName -> That way no error occurs and the displayName is added in the authentication state using Ngrx.

auth.actions.ts

// ... omitted
export class AuthUserPayload {
    constructor(public user: any) { 
        console.log(user); 
        // I have the feedback but the error occurs.
        // the error just does not happen when I do not assign the entire user object.


    }
}

app.module.ts:

AngularFireModule.initializeApp(environment.firebase),
AngularFireAuthModule,
AngularFirestoreModule.enablePersistence(),
AngularFireDatabaseModule
like image 772
Luiz Avatar asked Nov 07 '22 02:11

Luiz


1 Answers

For me, the issue seems to be a conflict with storeFreeze. Removing it from my metaReducers gets rid of the error. I haven't looked into it any further.

like image 117
whatsthatitspat Avatar answered Nov 13 '22 02:11

whatsthatitspat