【问题标题】:Firebase/Ionic: Type 'UserCredential' is not assignable to type 'User'. Property 'delete' is missing in type 'UserCredential'Firebase/Ionic:“UserCredential”类型不可分配给“User”类型。 “UserCredential”类型中缺少属性“删除”
【发布时间】:2019-02-04 19:45:36
【问题描述】:

我最近刚开始学习 Ionic 和 Firebase,并按照 Pluralsight 上的教程“使用 Firebase 身份验证服务手册对用户进行身份验证”。我遇到了一个错误,我认为可能是 Ionic 或 Firebase 的一个版本已过时,但在 google 之后我仍然不知道如何解决这个问题。

AuthProvider

import { Injectable } from '@angular/core';
import firebase from 'firebase';
import {User} from '@firebase/auth-types';

@Injectable()
export class AuthProvider {

  constructor() {

  }

  async signUpUser(email: string, password: string, firstName: string, lastName: string): Promise<any> {
    try {
      const newUser:User = await firebase
          .auth()
          .createUserWithEmailAndPassword(email, password);

      await firebase
          .database()
          .ref(`/userProfile/${newUser.uid}`)
          .set({email:email, firstName:firstName, lastName:lastName});
        return newUser;
    } catch (error){
      throw error;
    }
  }
}

它抛出“类型'UserCredential'不能分配给类型'User'的错误。 “UserCredential”类型中缺少属性“delete”。 "

【问题讨论】:

    标签: angular firebase ionic-framework firebase-authentication


    【解决方案1】:

    由于您的导入语句存在向后兼容性问题,这看起来是个问题

    import {User} from '@firebase/auth-types';
    

    解决方案 1)

    一) 通过以下方式修改 package.json 中的“firebase”条目: “火力基地”:“4.10.0”

    b) 删除 node_modules 文件夹

    c) 运行 npm install。

    解决方案 2)

      signUpUser(
        email: string,
        password: string,
        firstName: string,
        lastName: string
      ) {
        firebase
          .auth()
          .createUserWithEmailAndPassword(email, password)
          .then(function(userRecord) {
            firebase
              .database()
              .ref(`/userProfile/${userRecord.uid}`)
              .set({ email: email, firstName: firstName, lastName: lastName });
            return userRecord;
          })
          .catch(function(error) {
            throw error;
          });
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-24
      • 1970-01-01
      • 2019-06-04
      • 2017-12-05
      • 2019-06-22
      • 2018-07-06
      • 2021-10-04
      • 2018-11-11
      相关资源
      最近更新 更多