firebase实时数据库错误:Reference.set失败:第一个参数在属性

时间:2019-01-30 17:23:22

标签: javascript angular firebase angularfire2

在我的服务类中,我有一个创建新用户的方法。我需要在密钥等于新创建的用户的数据库中添加一个条目。我收到此错误Error: Reference.set failed: First argument contains undefined in property

import { Injectable } from '@angular/core';
import { User } from 'src/app/models/users.model';
import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
import { AngularFireAuth } from '@angular/fire/auth';
import * as firebase from 'firebase';
import { mapFireBaseListResponse } from '../helpers/functions/map-firebase-list-response';
import { removePropFromObject } from '../helpers/functions/remove-prop-from-object';
import { environment } from 'src/environments/environment';

@Injectable()
export class UsersService {

    path = '/users';
    listRef: AngularFireList<User>;

    constructor(
        private fireBase: AngularFireDatabase,
        private auth: AngularFireAuth
    ) {
        this.listRef = this.fireBase.list(this.path, ref => ref.orderByChild('active').equalTo(true));
    }

    getAllUsers = () => mapFireBaseListResponse(this.listRef);

    newUser = async (user: User) => {
        const authApp = firebase.initializeApp(environment.firebase, 'NewUser');
        const created = await authApp.auth().createUserWithEmailAndPassword(user.email, user.password);
        const newUser = await this.fireBase.list(`/users/${created.user.uid}`).set(
            created.user.uid,
            removePropFromObject(user, 'password')
        );
        authApp.auth().signOut();
        return newUser;
    }

    updateUser = (user: User) => this.listRef.update(user.key, removePropFromObject(user, 'key'));

}

0 个答案:

没有答案