无法使用Firebase使用正确的电子邮件地址和密码登录

时间:2019-09-01 04:53:12

标签: firebase vue.js firebase-authentication

我创建了一个用于毕业研究的Web应用程序(由Vue-js,vue-router开发)。我正在使用Firebase身份验证登录。即使使用正确的电子邮件地址和密码,我也无法登录,并且站点从“ localhost:8080 / signin”重定向到“ localhost:8080 / signin?”

这是使用Vue(2.6.10)和firebase开发的。

(ellipsis)
input(type="text" placeholder="your@email.com" v-model="email")#MailAddress
(ellipsis)
input(type="password" placeholder="password" v-model="password")#Password
(ellipsis)
import firebase from "firebase";

export default {
  name: "Signin",
  data() {
    return {
      email: "",
      password: ""
    };
  },
  methods: {
    signIn() {
      firebase
        .auth()
        .signInWithEmailAndPassword(this.email, this.password)
        .then(
          () => {
            alert("Success");
            this.$router.push("/");
          },
          err => {
            alert(err.message);
          }
        );
    }
  }
};

我希望重定向到'localhost:8080 /'

1 个答案:

答案 0 :(得分:0)

这对我有用。

在我的Vue组件中:

import firebase from '../database';

async signIn () {
  let result = await firebase.signIn(this.email, this.password);
  if (result.message) {
    this.error = result.message;
  } else {
    // Go to your route
  }
}

在我的数据库文件中:

const database = firebase.initializeApp(config);

database.signIn = async (email, password) => {
  try {
    await firebase.auth().signInWithEmailAndPassword(email, password);
    return true;
  } catch (error) {
    return error;
  }
};