1

我刚刚按照大部分 akita-ng-fire 示例 + doc 在我的 ionic 项目中设置身份验证。

我已经安装了@angular/fire(6.0.2)、akita-ng-fire(1.5.13)、firebase(7.19.1)、angular lib(10.0.0)、ionic libs(5.0.0)。

这是我的模型:

export interface Profile {
  displayName: string;
  photoURL: string;
  organizationIds: string[];
}

export function createProfile(profile: Partial<Profile>): Profile {
  return {
    displayName: '',
    photoURL: '',
    organizationIds: [],
    ...profile,
  };
}

这是我的查询:

import { Injectable } from '@angular/core';
import { Query } from '@datorama/akita';
import { AuthStore, AuthState } from './auth.store';

@Injectable({ providedIn: 'root' })
export class AuthQuery extends Query<AuthState> {
  profile$ = this.select('profile');
  userId$ = this.select((state) => state.profile.id);
  roles$ = this.select('roles');
  isLoggedIn$ = this.select((state) => !!state.profile); // check section "roles" below

  constructor(protected store: AuthStore) {
    super(store);
  }
}

这是我的商店:

import { Injectable } from '@angular/core';
import {  Profile } from './auth.model';
import {  Store, StoreConfig } from '@datorama/akita';
import { FireAuthState, RoleState } from 'akita-ng-fire';


export interface AuthState extends FireAuthState<Profile>, RoleState {}

const initialState: AuthState = {
  uid: null,
  profile: null,
  roles: {},
  loading: false,
  emailVerified: false,
};

@Injectable({ providedIn: 'root' })
@StoreConfig({ name: 'auth' })
export class AuthStore extends Store<AuthState> {
  constructor() {
    super(initialState);
  }
}

这是我的服务:

import { Injectable } from '@angular/core';
import { AuthStore, AuthState } from './auth.store';
import { CollectionConfig, FireAuthService } from 'akita-ng-fire';
import { createProfile } from './auth.model';

@Injectable({ providedIn: 'root' })
@CollectionConfig({ path: 'users' })
export class AuthService extends FireAuthService<AuthState> {
  formatFromFirestore = createProfile;

  constructor(store: AuthStore) {
    super(store);
  }

  onCreate() {
    console.log('Logged from onCreate hook');
  }

  onDelete() {
    console.log('Logged from onDelete hook');
  }

  onUpdate() {
    console.log('Logged from onUpdate hook');
  }

  onSignup() {
    console.log('Logged from onSignup hook');
  }

  onSignin() {
    console.log('Logged from onSignin hook');
  }

  onSignout() {
    console.log('You have been signed out. Logged from onSignout hook');
  }
}

我已经在我的 app.module 中设置了环境的 firebase + 初始化的 firebase。

但是,在我的应用程序中,我正在尝试调用该服务:

  async doLogin() {
    await this.authService.signup('aaa@bbb.com', 'xxxyyyzzz');
    await this.authService.signin('aaa@bbb.com', 'xxxyyyzzz');
  }

我在 chrome 开发工具中收到此错误:

[WDS] Live Reloading enabled. core.js:4197 ERROR Error: Uncaught (in promise): TypeError: this.fireAuth.auth.createUserWithEmailAndPassword is not a function TypeError: this.fireAuth.auth.createUserWithEmailAndPassword is not a function
    at AuthService.<anonymous> (akita-ng-fire.js:1181)
    at Generator.next (<anonymous>)
    at tslib.es6.js:74
    at new ZoneAwarePromise (zone-evergreen.js:960)
    at __awaiter (tslib.es6.js:70)
    at AuthService.signup (akita-ng-fire.js:1179)
    at AppComponent.<anonymous> (app.component.ts:80)
    at Generator.next (<anonymous>)
    at tslib.es6.js:74
    at new ZoneAwarePromise (zone-evergreen.js:960)
    at resolvePromise (zone-evergreen.js:798)
    at zone-evergreen.js:705
    at rejected (tslib.es6.js:72)
    at ZoneDelegate.invoke (zone-evergreen.js:364)
    at Object.onInvoke (core.js:27436)
    at ZoneDelegate.invoke (zone-evergreen.js:363)
    at Zone.run (zone-evergreen.js:123)
    at zone-evergreen.js:857
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Object.onInvokeTask (core.js:27424)

我能错过什么?如何初始化身份验证?我到处找,但我找不到我错过的东西。

this.authService在调用它之前已经抛弃了它,我正在寻找一个fireAuth属性,但下面没有身份验证。是否存在某种不兼容?

4

0 回答 0