firebase.auth().createUserWithEmailAndPassword Undefined is not a function

前端 未结 5 924
别那么骄傲
别那么骄傲 2020-12-03 15:36

I am following the firebase documentation on user management

var firebase = require(\'firebase\');

// Initialize Firebase
firebase.initializeApp({
    servi         


        
5条回答
  •  庸人自扰
    2020-12-03 16:04

    I am not sure this is correct, but it helps:

    1. In console.firebase.google.com get script:

    and Config:

    var config = {
        apiKey: "xxxxxxxxxxxxxxx",
        authDomain: "project-nnnnnnnnnnn.firebaseapp.com",
        databaseURL: "https://project-nnnnnnnnnnn.firebaseio.com",
        storageBucket: "project-nnnnnnnnnnn.appspot.com",
    };

    1. Copy firebase.js file from

    to local project fb/firebase.js

    1. In firebas-service.ts:

        var firebase = require('./fb/firebase');
    // Initialize Firebase
    var config = {
        apiKey: "xxxxxxxxxxxxxxx",
        authDomain: "project-nnnnnnnnnnn.firebaseapp.com",
        databaseURL: "https://project-nnnnnnnnnnn.firebaseio.com",
        storageBucket: "project-nnnnnnnnnnn.appspot.com",
    };
    firebase.initializeApp(config);
    
    export function createUser (email : string, password:string){
        firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
            if (error.code){
                // Handle Errors here.
                var errorCode = error.code;
                var errorMessage = error.message;
                alert(errorMessage);
                console.log(errorMessage);
            }
            else{
                // ...
            }
        });
    }

提交回复
热议问题