【问题标题】:_firebase_config__WEBPACK_IMPORTED_MODULE_3__.default.createUserWithEmailAndPassword is not a function in Vue Js_firebase_config__WEBPACK_IMPORTED_MODULE_3__.default.createUserWithEmailAndPassword 不是 Vue Js 中的函数
【发布时间】:2021-09-18 16:31:38
【问题描述】:

createUserWithEmailAndPassword 函数对我不起作用。以下是我的代码-

config.js

import firebase  from 'firebase/app'
import 'firebase/firestore'
import 'firebase/auth'

const firebaseConfig = {
    apiKey: "AIzaSyBD8W5T7ZSvryW2TNSWOgoCO3EpyV6i65o",
    authDomain: "vue-firebase-site-eb79e.firebaseapp.com",
    projectId: "vue-firebase-site-eb79e",
    storageBucket: "vue-firebase-site-eb79e.appspot.com",
    messagingSenderId: "657936011344",
    appId: "1:657936011344:web:a2498d2fe27f951b6b8155"
  };


firebase.initializeApp(firebaseConfig)

const projectAuth = firebase.auth();
const projectFirestore = firebase.firestore();
const timeStamp = firebase.firestore.FieldValue.serverTimestamp

export default { projectAuth, projectFirestore, timeStamp }

使用SignUp.js

import { ref } from "vue"
import projectAuth from '../firebase/config'

const  error = ref(null)

const signup = async (email,password,displayName) => {
    error.value  =  null

    try {
        const res = await projectAuth.createUserWithEmailAndPassword(email, password)
        console.log(res)
        if(!res){
            throw new Error('Could not complete the signup')
        }
        await res.user.updateProfile({displayName})
        error.value = null
        return res
    } catch (err) {
        console.log(err.message)
        error.value = err.message
    }
}

const useSignup = () =>{

    return{error, signup}
}

export default useSignup

尝试了很多东西-

  1. 删除节点模块并重新安装。
  2. 同时更改 Firebase 的版本

任何解决方案都不适合我。

提前致谢!!

【问题讨论】:

    标签: javascript firebase vue.js firebase-authentication vuejs3


    【解决方案1】:

    当您在useSignUp.js 中导入config.js 文件时,您将整个对象设置为projectAuth

    你需要做的是:

    import { projectAuth } from '../firebase/config' // just get projectAuth variable from config.js
    

    编辑:

    还有另一种解决方法:

    import firebaseConfig from '../firebase/config' 
    

    然后在try 块内使用这个:

    const res = await firebaseConfig.projectAuth.createUserWithEmailAndPassword(email, password)
    

    【讨论】:

    • "在 '../firebase/config' 中找不到导出 'projectAuth' 得到这个
    • config.js 中尝试console.log(projectAuth) 看看它记录了什么
    • 您正在导入的文件正确(尝试交叉检查一次)
    • 是的,检查了我正在导入的正确文件。
    • const res = await firebaseConfig.projectAuth.createUserWithEmailAndPassword(email, password) this 1
    猜你喜欢
    • 2021-03-14
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 2021-06-10
    • 2021-05-10
    • 2018-12-18
    • 2019-04-08
    相关资源
    最近更新 更多