Lui*_*uiz 5 firebase typescript firebase-authentication ngrx angularfire2
我正在登录我的应用程序,登录成功完成后,我调用一个操作来更改我的应用程序的状态,以接收Firebase Authentication的已认证用户的数据。
当我尝试将整个对象传递给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)
Run Code Online (Sandbox Code Playgroud)
当我constructor(user: any)从Firebase服务器返回的整个对象开始执行操作时,就会发生这种情况。
但是,如果我使用以下方法访问对象的其他属性:(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 })))
))
);
Run Code Online (Sandbox Code Playgroud)
res.user- >错误错误(调用方法signInWithEmailAndPassword(电子邮件,密码)时,返回Firebase)
res.user.displayName- >这样就不会发生错误,并且可以使用Ngrx在身份验证状态下添加displayName。
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.
}
}
Run Code Online (Sandbox Code Playgroud)
app.module.ts:
AngularFireModule.initializeApp(environment.firebase),
AngularFireAuthModule,
AngularFirestoreModule.enablePersistence(),
AngularFireDatabaseModule
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
184 次 |
| 最近记录: |