简体   繁体   English

Firebase.auth示例不起作用

[英]Firebase.auth Example Not Working

I'm trying to add very basic authentication for my test Firebase site using this example: 我正在尝试使用以下示例为我的测试Firebase网站添加非常基本的身份验证:

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

I get an error 'Firebase.auth failed: Was called with 0 arguments. 我收到错误消息“ Firebase.auth失败:使用0个参数调用。 Expects at least 1.' 期望至少为1。

myDB is a reference like : new Firebase(' https://myDB.firebaseio.com '); myDB的引用类似于:new Firebase(' https://myDB.firebaseio.com ');

I am using version 2.4.2." https://cdn.firebase.com/js/client/2.4.2/firebase.js "> 我正在使用2.4.2版。“ https://cdn.firebase.com/js/client/2.4.2/firebase.js ”>

How can I get this simple example working? 如何使这个简单的示例正常工作?

You are using a very old Firebase version, please update to the latest version: 您使用的Firebase版本非常旧,请更新至最新版本:

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

more info here: 更多信息在这里:

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

then configure the firebase project and initialize it: 然后配置firebase项目并对其进行初始化:

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() : 然后您可以使用firebase.auth()

https://firebase.google.com/docs/reference/js/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. 同样,在登录之前,您需要使用createUserWithEmailAndPassword(email, password)对帐户进行身份验证。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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