0

Screenshot-1
enter image description here

Screenshot-2
enter image description here

I am trying to check in the database whether there is a user with such a login or not. If it exists, then display an error.How can I get a response from the database before I create a user

Kuldeep J
  • 382
  • 5
  • 12
danixxx
  • 3
  • 2

1 Answers1

0

That's not an efficient way of handling authentication. The best option that you have in my opinion, would be to implement Firebase Authentication. Once you do that, you can simply check if the user is authenticated or not. How? By simply checking if the FirebaseUser object is null or not. Please also note that this operation is not asynchronous.

If you however need to get something from the Realtime Database, then please note that that is indeed an asynchronous operation. Since you're using Kotlin, the following article will help for sure:

How to read data from Firebase Realtime Database using get()?

Edit:

If you want to check if a user already exists, then please check my answer from the following post:

Besides that, never store credentials in plain text. I highly recommend you implement Firebase Authentication so you can secure your database using Firebase Security Rules. If you want to keep your own authentication mechanism, please see the official document regarding that:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • I have a Firebase auth implementation (mail and password). But in addition to the email and password, I also need to store the rating and login in the database. Therefore, I enter the user into the database and add his username and password, and then I need to find a duplicate login – danixxx Apr 29 '22 at 07:58
  • https://i.postimg.cc/4yV0Drj8/image.png – danixxx Apr 29 '22 at 08:01
  • https://i.postimg.cc/Cx3q1X2C/image.png – danixxx Apr 29 '22 at 08:01
  • Please check my updated answer. Is it clear now? – Alex Mamo Apr 30 '22 at 09:49