Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
Firebase transaction deletes node

When user makes an in-app purchase, I want their tokens count to decrement by the cost. This will just delete the user's tokens

(This code used to work and broke recently)

    var senderRef = db.ref(`users/${sender.id}/tokens`)
    var amount = 1000
    var tokensCount =  await (await senderRef.once('value')).val()
    console.log("SENDER TOKENS: ", tokensCount, sender.id)
    await senderRef.transaction(async function(currentTokens) {
        var newAmount = currentTokens - amount
        if (newAmount >= 0) {
            return newAmount
        } else {
            return 
        }
    }).then(async (result) => {
        var tokensCount = await (await senderRef.once('value')).val()
        console.log("SENDER TOKENS AFTER TRANSACTION: ", tokensCount, sender.id)
    })

I have data structured as: enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!