user9958772
user9958772

Reputation: 147

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 :

Upvotes: 0

Views: 87

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598877

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, "[email protected]", "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.

Upvotes: 1

Related Questions