Skip to content
Advertisement

_firebase_config__WEBPACK_IMPORTED_MODULE_3__.default.createUserWithEmailAndPassword is not a function in Vue Js

createUserWithEmailAndPassword function is not working for me. Below are my code –

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 }

useSignUp.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

Tried a number of things-

  1. Delete node modules and install them again.
  2. Change the version of firebase as well

Nothing working for me any solutions are appreciated.

Thanks in Advance!!

Advertisement

Answer

when you importing the config.js file inside useSignUp.js you are setting the whole object as projectAuth

what you need to do is following:

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

edit:

There is another way to work this around:

import firebaseConfig from '../firebase/config' 

then inside the try block use this:

const res = await firebaseConfig.projectAuth.createUserWithEmailAndPassword(email, password)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement