使用电子邮件和密码 firebase 以角度硬编码登录

时间:2021-07-17 17:37:36

标签: javascript firebase firebase-authentication

我想使用我的 angular webapp 对用户进行身份验证,而无需用户注册帐户。一开始我尝试匿名登录,但这创建了太多匿名用户。我正在考虑在我的代码中创建一个用户并使用硬编码的电子邮件和密码登录,但这会在控制台中公开电子邮件和密码。坏人是否可以使用他们在控制台中找到的电子邮件和密码做任何事情,例如他们可以通过 REST API 使用我的数据库访问我的数据库,还是有更好的方法来做到这一点?

我的代码:

  constructor(private afAuth: AngularFireAuth) { 
    this.afAuth.auth.signInWithEmailAndPassword("test@email.com","helloworld")
    .then((user) => {
      this.authState = user
    })
    .catch(error => console.log(error));
  }

控制台:

Request URL: https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=APIKEY

{email: "test@email.com", password: "helloworld", returnSecureToken: true}
email: "test@email.com"
password: "helloworld"
returnSecureToken: true

1 个答案:

答案 0 :(得分:1)

为此,您可以使用 Firebase 的“匿名使用 Firebase 进行身份验证”功能。 您可以从以下位置关注官方文档:https://firebase.google.com/docs/auth/web/anonymous-auth