davy
davy

Reputation: 4562

Firebase.auth Example Not Working

I'm trying to add very basic authentication for my test Firebase site using this example:

 myDB.auth().signInWithEmailAndPassword(email, password).catch(function (error) {
        // stuff
  }

I get an error 'Firebase.auth failed: Was called with 0 arguments. Expects at least 1.'

myDB is a reference like : new Firebase('https://myDB.firebaseio.com');

I am using version 2.4.2."https://cdn.firebase.com/js/client/2.4.2/firebase.js">

How can I get this simple example working?

Upvotes: 0

Views: 1311

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80952

You are using a very old Firebase version, please update to the latest version:

<script src="https://www.gstatic.com/firebasejs/4.12.0/firebase.js"></script>

more info here:

https://firebase.google.com/support/release-notes/js

then configure the firebase project and initialize it:

var config = {
apiKey: "<API_KEY>",
authDomain: "<PROJECT_ID>.firebaseapp.com",
databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
storageBucket: "<BUCKET>.appspot.com",
messagingSenderId: "<SENDER_ID>",
 };
 firebase.initializeApp(config);

then you can use firebase.auth():

https://firebase.google.com/docs/reference/js/firebase.auth

and use the sign in method:

firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
  // Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
 });

Also before Sign in you need to use createUserWithEmailAndPassword(email, password) to authenticate the account.

https://firebase.google.com/docs/auth/web/start

Upvotes: 3

Related Questions