Check value existance in FB db after store value

my current mini project where, firstly few passcodes store into firebase db and structure will be like below;


below blocks will store the passcode into firebase db

on the other side, i want to know if the passcode existed in the same firebase db.
i will keyin correct passcode then a shape will appear else if wrong passcode the shape will not appear
i have tried below blocks but seems not working, think mostly the logical all wrong :sweat_smile:
any guide here will be much appreciated :folded_hands:

try like this.

Get the json data from the bucket passcode (using this as tag name)
then convert the passcode key value as a list, then compare the entered text with Is in list block.
If exits throw an error alert
else proceed to save under proper project bucket
(this method will save multiple times of calling fb data)


hi @Still-learning, thank you for your suggestions but may i know the generator blocks is for what purposes ya? :thinking:

@Still-learning
but actually these two are separate in different app; first app will be the one person post the passcodes to the firebase, and second app is for people to key in the passcode (after they receive the passcode) in order to go to another screen.
so second app is where the passcode checking function comes in at the background.

I dont think your logic is good. Modify your logic. Without knowing the person whose id how can you check the passcode given to him?

The above blocks is used to check whether the entered passcode is existing in the fb ir not.

What will you do if they same passcode given to multiple users?

In app 1 generate passcode for the particular user using his id or any other key value and store it.

In second app, when user tried to login or entered his passcode using his id or key vakue, run set the bucket as passcode/userKey and get the key value of passcode and check the obtained value with input value

hi @Still-learning thank you for your response above.

the scenario is like this:

  1. user will definitely signin with Gmail account and proceed to register page (app 1)
  2. they need do a simple register and pay to get the passcode (app 1)
  3. admin once received register, admin will then post a passcode into firebase db (app 2)
  4. admin will then email the passcode to the user
  5. user will key in the received passcode in app 1 in order to proceed to another page (app 1)
  6. user will then start using the system n etc (app 1)

:white_check_mark: Flow Summary

  1. User logs in via Gmail (App 1)
  2. User registers and pays (App 1)
  3. Admin sees the registration (App 2)
  4. Admin enters a passcode into Firebase (App 2)
  5. Admin sends email with passcode (App 2)
  6. User enters passcode to verify and unlock system (App 1)

:wrench: App 1 (User App) - Detailed Logic

1. Sign in with Gmail

  • Use Google Sign-In component or Firebase Authentication (with Gmail only).
  • Save user email or UID in TinyDB for later steps.

2. Register and Pay

  • Create a simple registration form (name, email auto-filled, phone, etc).
  • After submission, use Firebase Database to store:
/registrations/[user_email] = {
   name: ..., phone: ..., status: "pending", passcode: ""
}
  • Redirect user to payment gateway (Airtel, bKash, SSLCommerz, etc).
  • After payment success, display “Please wait for admin approval.”

3. Passcode Entry Page

  • Create a textbox to enter the passcode.
  • When user enters passcode, check it from Firebase:
/passcodes/[user_email] = "SOME-CODE"
  • If match: unlock next screen and store a flag in TinyDB like AccessGranted = true

:man_office_worker: App 2 (Admin App) - Logic

1. See Pending Registrations

  • Load Firebase /registrations where status = "pending"

2. Review & Generate Passcode

  • Show list of users waiting approval.
  • Admin enters passcode for a user.
  • Store into:
/passcodes/[user_email] = "ABC123"
/registrations/[user_email]/status = "approved"
/registrations/[user_email]/passcode = "ABC123"

3. Send Email

  • Use a web API or Gmail script (Apps Script) to send email:
    • To: user_email
    • Subject: Your App Passcode
    • Body: Your passcode is: ABC123

:locked_with_key: Security Tips

  • Use Firebase rules:
{
  "rules": {
    "registrations": {
      ".read": "auth != null",
      ".write": "auth != null"
    },
    "passcodes": {
      ".read": "auth != null && auth.token.email == $email",
      ".write": "auth.token.admin == true"
    }
  }
}
  • Or manually restrict in app by using user email comparison.

also

:sparkles: Updated Logic in Blocks:

Here’s how you can refactor it:

:package: On Submit Passcode Button:

1. set global passcode_keyin to enter_passcode.Text
2. set Firebase_Database1.ProjectBucket to "passcode"
3. call Firebase_Database1.GetTagList

:package: When Firebase_Database1.TagList

for each item in value:
   call Firebase_Database1.GetValue
     tag: join item and "/passcode"
     valueIfTagNotThere: "NOT_FOUND"

:package: When Firebase_Database1.GotValue

if value = global passcode_keyin:
   set color_shape.Visible to true
   (optional: set a global flag like passcodeFound = true to stop further checking)
else:
   set color_shape.Visible to false

:warning: Tips:

  • Make sure Firebase passcode values are saved as plain strings (not with extra quotes like '"43516"'). That’s why you see double quotes. Fix this by changing store block to:
valueToStore: trim(passcode.Text)
  • Use the trim() block to clean input and fetched value before comparing.

This can be done automatically no manual intervention is required!

Payment received > passcode is stored in firebase RTDB + an email with same passcode sent to the user. [Paid $4] Send Single/Bulk Email(s) Using Personal Single/Multiple Gmail Id(s) | Send Any Type Of Attachment | Free Unlimited Email OTP Solution |

Hi @Mike_Chan, I can help you. DM me.

hi @Glich, it doesn’t work :sweat_smile:

now the tag i use different

i tried with below sill not working

In the get value remove the code tag and set it as empty and run

hi @Still-learning, r u saying like this? but still nothing.
is it somewhere i missed out?
do i need to initialize the firebase bucket, URL and token?

FYI, the below firebase value was posted from different app

supposed the color component should appear if the code entered by user matches with firebase db’s existing value, else nothing happen.

UPDATE
my project name is different from the firebase db name but in the Project Settings, the app name and the package name already follow back the firebase’s. is this the issue?



:backhand_index_pointing_down: below is from my firebase project setting

@Mike_Chan I think it’s quite easy somehow but also difficult. First thing, you must have specific user IDs, email etc stored in Firebase, when user request pass code you must approve that payment made was a successful, then send the pass code using the store user data to deliver the code the right user, then use when Firebase database data changed block +itool for the specific user, notify them when the code was sent to user email, [FREE] Email OTP Verification[UNLIMITED]

Sorry maybe I made more difficult now​:joy::joy::folded_hands:

But it’s 100% possible if you have user IDs in your Firebase

Hi @Ibrahim_Jamar, good day to you and thanks for the guides and heads up above.
But for now what i planned to do is abit manual, for the moment where once the user paid i will email out myself the passcode to him/her (after i updated new passcodes into FB) :sweat_smile:
Haha, not to say difficult but also need for later automation in the future.

OK @Mike_Chan so every time user requests passcode you gonna visit your fd​:joy::joy: that’s pretty cool but takes much energy. Let me try cooking something maybe it will help somehow

hi @Ibrahim_Jamar thanks for your motivation but for now i wana focus on testing the passcode checking from firebase when user key in the provided passcode :crossed_fingers:

Oky i got you

@Mike_Chan
Here are the correct blocks.


Firebase structure: