简体   繁体   中英

Exception raised with createUserWithEmailAndPassword

Can someone explain if any issue has been reported with the Firebase Authentication Javascript SDK.

Every time I try to create a new account with:

import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";

const auth = getAuth();
createUserWithEmailAndPassword(auth, email, password)
  .then((userCredential) => {
    // Signed in 
    const user = userCredential.user;
    // ...
  })
  .catch((error) => {
    const errorCode = error.code;
    const errorMessage = error.message;
    // ..
  });

it raises the following error:

TypeError: Cannot read properties of undefined (reading 'then')

My settings:

  • I am using Firebase 9
  • Firebase is initialised correctly with the configuration settings
  • the Sign-In Method: Email/Password is enabled in the console

I'm not sure why the code you shared isn't working, but the v9.15 SDK is working without problems for me here: https://stackblitz.com/edit/auth-v9?file=index.js

Code:

const auth = getAuth();
createUserWithEmailAndPassword(auth, "user@domain.com", "password").then((credentials)=> {
  console.log(credentials);
  console.log(credentials.user);
}).catch((err) => {
  console.error(err);
})

This logs:

Initializing Firebase

UserCredentialImpl {user: UserImpl, providerId: null, _tokenResponse: {…}, operationType: 'signIn'}

UserImpl {providerId: 'firebase', proactiveRefresh: ProactiveRefresh, reloadUserInfo: {…}, reloadListener: null, uid: '9X2qcCSN9vU4K2IhBSWExW3Hlix1', …}

Which looks correct to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM