Please help me with this code!

So, the thing is, I want to know if the email, registered through direct method is signing up or signing in user.

and It’s possible
if I can check if firebase DATABASE have the email registered or not.

I’m saving data from User ID, but when user sign in thorugh google again NEW User id will be created, from same EMAIL.

I don’t want that to happen,

So, please tell me how can I check if user is signing up or logging in.


Typically I wouldn’t use Firebase as a Database, mostly because the connection between Thunkable and Firebase is used only for authentication. Instead, use Google Sheets as an alternative to have the ability to access and change the spread.

Let me explain further into detail what you can do (scroll down if you want to skip this):
Whenever the Google account is recorded onto the app with the get profile from Google block, you can add a new row containing whatever info you need later on in your app. The Google account will actually stay signed in even if you close the app until you call a command that signs out your Google account. You can set variables for the blocks like User ID, Display name, Profile photo image URL and others too.

Whenever the “Sign in with Google” block is clicked, you can append a new row with all your variables. The next time someone signs in with the same account, grab a block that can search through your data and look if the account has been created already or not.

when google Click:
  set stored variable auth method to "Google"
  get profile from Google:
    if inputEmail ≠ list of values in (spreadsheet) in Sheet1 in Default View in (specific column):
      create row in (spreadsheet):
        "Insert variables into placeholders"
      call Alert1 Show:
        with output - was confirmed
        set Alert1 message to "Welcome!"
        then do:
          navigate to Form1
    else:
      call Alert1 Show:
        with output - was confirmed
        set Alert1 message to "Welcome back!"
        then do:
          navigate to Form1
    "Then continue your code below"

If you need any more help, let me know or contact Thunkable Staff and more reliable help.

1 Like

I wanted to use firebase for speed and real time sync.
Thanks for your idea of google sheets btw!
But I think firebase is more faster for real time data and sync.

1 Like

I asked @tatiang about the reliability between Firebase and Google Sheets. While Firebase has better security, Google Sheets has more ease of usage. And while you are correct for real time data sync, Google Sheets updates every second. As long as your Google Account is connected with Thunkable and your Drive is accessible, it should work the same. Firebase gives a more complex but thorough state in the Realtime Database, while Google Sheets is just for storing a little bit of data.

Try this out and see how it goes; please do not delete your original code. Keep it unattached from a when block and insert your new code that I have provided. Good luck!

Used, firebase API, connected it and got a dictionary from DB,
NOW,

The question is how to read a value of a dictionary?

Here is something you could use:

1 Like

Google sheets is

  • slow
  • not good for storing large data

and I’m using firebase for better security and efficiency.
Your idea about google sheet was good, but only is

  • The app is not going to include a large group of people.

I used firebase according my need. But if it was a small scale app, I’d for sure consider your idea!

Exactly what I meant!

By any chance you know how to

read data from a dictionary? tht too through a loop?

It is not my opinion to choose your chosen database. Google Sheets and Firebase can do the same things. I’m not specialized in using a proper database through Firebase. You may want to contact the support team for more help, unless I find a better solution.

Could you show me your code on how you implemented this?

Sure!

used firebase API, jumped directly to the users section through it!

then made THUNKABLE CODE looked like:

and got this

as result

If I find the solution myself, I’ll post it here and mark it as solution!

1 Like

For sure! I’m sorry that I can’t help much, but I sincerely hope someone actually does help. Good luck on completing this! I will continue to look for an answer ASAP.

1 Like

Thanks for your kind efforts!

1 Like

My reason for using Google Sheets is to insert it into a Data List/Grid viewer. That’s also one of the main reasons why I actually don’t use Firebase. Maybe soon it can change. I will put it as a feature request (check my profile later on this week)

1 Like

Sure!

You can paste that JSON text into Best JSON Viewer and JSON Beautifier Online on the left side and then on the right side click on a property such as “email” to see the path to that property. You can use get property of object blocks in Thunkable to extract the values you need.

If you’re trying to loop through multiple entries like that, it’s best to paste the full JSON response as text (not a screenshot) in a post here. Make sure to format the text using the </> in the forum toolbar above your post. That will remove smart quotes that prevent the code beautifier site from reading the JSON.

Whole JSON from directly firebase:

{
  "Data": {
    "exampleKey": "exampleValue",
    "users": {
      "105911822131142675060": {
        "email": "work7002@gmail.com"
      },

      "925911822131142675460": {
        "email": "school7002@gmail.com"
      }
    }
  },
  "organization": {
    "kuro": "sfjg"
  },
  "thunkableAccess": true
}

What I got using API:

{"105911822131142675060":{"email":"work7002@gmail.com"},
"925911822131142675460": {"school7002@gmail.com"}}

After using FIREBASE API this is where I got.
I want to check if email is already in the Database or not.

If it is then under what userID (the numerical code)