无法使用Ngrx读取未定义的属性“ firebaseApp”

时间:2018-08-31 04:10:54

标签: typescript firebase firebase-authentication angularfire2 ngrx

分配了完整的Firebase身份验证返回时出错

我正在登录我的应用程序,登录成功完成后,我调用一个操作来更改我的应用程序的状态,以接收 Firebase身份验证的身份验证用户的数据。

当我尝试将整个对象传递给user时,会发生以下错误:

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)

当我从Firebase服务器返回的整个对象中启动constructor(user: any)时发生这种情况。

但是,如果我使用(id, displayName, email)访问对象的其他属性,则不会发生此错误,仅当我尝试分配返回的整个对象时才会发生。

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 ->错误发生(调用该方法时返回Firebase   signInWithEmailAndPassword(电子邮件,密码)

     

res.user.displayName ->这样就不会发生错误并且displayName   使用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

1 个答案:

答案 0 :(得分:0)

对我来说,问题似乎与storeFreeze冲突。从我的metaReducers中删除它摆脱了错误。我没有进一步调查。