Skip to content

sendpulse.init returns wrong account (somehow persists) #35

Description

@Stas-Buzunko
  • I have clients with their SendPulse accounts
  • I have firebase cloud functions as backend

Use case:

  1. Client A calls endpoint - everything is good
  2. Client B calls the same endpoint before that function is off - sendpulse uses Client A credentials.

I've tried everything:

  1. i import sendpulse inside function
  2. I create a new directory every time !!!
  3. I remove old directory every time

sendpulse.init receives correct API_USER_ID and API_SECRET every time but returns wrong data

exports.smsBalance = functions.https.onCall(async (data, context) => {
  const { companyId } = data

  const { API_USER_ID, API_SECRET } = await admin.database().ref('SendPulse/' + companyId)
                                                        .once('value')
                                                        .then(s => s.val())

  const TOKEN_STORAGE = tempy.directory()

  const sendpulse = require("sendpulse-api")

  console.log(companyId, API_USER_ID, TOKEN_STORAGE)

  return new Promise(resolve =>
    sendpulse.init(API_USER_ID,API_SECRET,TOKEN_STORAGE, () =>
      sendpulse.getBalance(
        (data) => {
          resolve(data.balance_currency)
        },
        'UAH'
      )
    )
  )
})
.then(() => {
    rimraf(TOKEN_STORAGE, () => console.log('cleaned up'))
  })

I have no idea how to fix this. help appreciated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions