我无法登录。即使我在Firebase中输入了电子邮件和密码,它仍然会保持Saying Error Logging

问题描述 投票:0回答:2

自开始以来,电子邮件/密码登录提供商的状态始终为“已启用”。但它仍然给我同样的错误。即使从Firebase中的身份验证显示:1。将您的应用程序连接到Firebase - >已连接(绿色检查)2。将Firebase身份验证添加到您的应用程序 - >正确设置依赖关系(绿色检查)

我尝试使用我输入Firebase的电子邮件和密码登录,但仍无法登录。它告诉我吐司:

登录时出错:(

我一直试图从互联网上找到解决方案。这是我目前的代码:

04-14 18:46:05.238 9631-9631/com.adrian.projectadrian E/Login Error: signInWithEmailAndPassword
    com.google.firebase.auth.FirebaseAuthException: The given sign-in provider is disabled for this Firebase project. Enable it in the Firebase console, under the sign-in method tab of the Auth section.
        at com.google.firebase.auth.api.internal.zzdr.zzb(Unknown Source)
        at com.google.firebase.auth.api.internal.zzey.zza(Unknown Source)
        at com.google.firebase.auth.api.internal.zzeo.zzc(Unknown Source)
        at com.google.firebase.auth.api.internal.zzeq.onFailure(Unknown Source)
        at com.google.firebase.auth.api.internal.zzdx.dispatchTransaction(Unknown Source)
        at com.google.android.gms.internal.firebase_auth.zza.onTransact(Unknown Source)
        at android.os.Binder.execTransact(Binder.java:453)
package com.adrian.projectadrian

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.EditText
import android.widget.Toast
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.FirebaseApp
import com.google.firebase.auth.AuthResult
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    var mAuth = FirebaseAuth.getInstance()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        FirebaseApp.initializeApp(this)
        setContentView(R.layout.activity_main)

        login_btn.setOnClickListener(View.OnClickListener {
            login()
        })
    }

    private fun login() {
        val emailTxt = findViewById<View>(R.id.email) as EditText
        var email = emailTxt.text.toString()
        val passwordTxt = findViewById<View>(R.id.password) as EditText
        var password = passwordTxt.text.toString()
        if (!email.isEmpty() && !password.isEmpty()) {
            this.mAuth.signInWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, OnCompleteListener<AuthResult> { task ->
                    if (task.isSuccessful) {
                        startActivity(Intent(this, home::class.java))
                        Toast.makeText(this, "Successfully Logged in :)", Toast.LENGTH_LONG).show()
                    } else {
                        Log.e("Login Error", "signInWithEmailAndPassword", task.getException())
                        Toast.makeText(this, "Error Logging in :(", Toast.LENGTH_SHORT).show()
                    }
                })

        } else {
            Toast.makeText(this, "Please fill up the Credentials :|", Toast.LENGTH_SHORT).show()
        }
    }
}

预期结果是它可以指引我到主页。

android firebase kotlin firebase-authentication
2个回答
1
投票

编辑后,我们现在可以看到这是错误消息:

此Firebase项目已禁用指定的登录提供程序。在“身份验证”部分的“登录方法”选项卡下的Firebase控制台中启用它。

因此,您尚未启用您尝试登录的提供商。解决方案是转到Firebase Authentication console并启用该提供程序。


原始回复:

如果Task失败,则它包含一个例外,其中包含有关失败的详细信息。您应该记录该异常以找出登录失败的原因。

this.mAuth.signInWithEmailAndPassword(email, password)
    .addOnCompleteListener(this, OnCompleteListener<AuthResult> { task ->
        if (task.isSuccessful) {
            startActivity(Intent(this, home::class.java))
            Toast.makeText(this, "Successfully Logged in :)", Toast.LENGTH_LONG).show()
        } else {
            Log.e("Login Error", "signInWithEmailAndPassword", task.getException());
            Toast.makeText(this, "Error Logging in :(", Toast.LENGTH_SHORT).show()
        }
    })

使用上面的代码,您可以在应用程序的logcat输出中找到异常。


0
投票

所以我做的是下载另一个

google-services.json

并将其替换为Die

app

并改变这一点

    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.1'

在我的build.gradle(模块:应用程序)中,这解决了我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.