首页 > 解决方案 > Hardcode sign in with email and password firebase in angular

问题描述

I want to authenticate users using my angular webapp without the users needing to sign-up for an account. At first I tried sign in anonymously but that created too many anonymous users. I am thinking about create an user and sign in with hardcoded email and password in my code but that exposes the email and password in the console. Can bad guys do anything with the email and password they find in the console like can they access my database with that via REST API or is there a better way to do this?

My code:

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

Console:

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

标签: javascriptfirebasefirebase-authentication

解决方案


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


推荐阅读