#luftie-missing-apikey

1 messages · Page 1 of 1 (latest)

covert gullBOT
static hemlock
#

Hello

#

Yeah if you can provide more details I'd be happy to help

wise swan
#

Yes sure, givw me only a moment I am AFK.

covert gullBOT
wise swan
#

Ok, I'm back so the thing is that while authentication of an user I want to create for him an stripe account object and an link for the user to login into dashboard in order to call futher actions and so forth. The problem is that instead of the desired response, that is given in stripe api docs, I get an empty object in both cases. index.js: ```js
exports.createAccount= functions.https.onCall(async (req)=>{
try {
const account = await stripe.accounts.create({
type: "express",
settings: {
payouts: {
schedule: {
interval: "manual",
},
},
},
metadata: req.data.accountData,
});
return account;
} catch (err) {
console.log(err);
return err;
}
});

exports.createAccountLink=functions.https.onCall(async (req)=>{
try {
const {accountId} = req.data;
const accountLinkObject = await stripe.accountLinks.create({
account: accountId,
type: "account_onboarding",
refresh_url: https://bookfreak.org,
return_url: "https://bookfreak.org",
});
return {accountLinkObject};
} catch (error) {
console.log(error);
return {error};
}
}); ```

static hemlock
#

Where do you see an empty object exactly?

#

You aren't logging the object anywhere in that code?

wise swan
#

Sorry.

#

Missclick

wise swan
static hemlock
#

Okay well then first thing to do is add logging to the backend to ensure the objects are created there

#

So right before return account and return {accountLinkObject} you should add a log for those things

wise swan
#

All right, I suspect that it won't be visible in the developer console, but at least we can give it a try, ok.

static hemlock
#

Yeah you would need to look at your backend logs for that

#

It won't be in your web dev console

wise swan
#

Could you tell me what backend logs you mean. I don't know if i emphasized, but I do not work in a test-mode anymore.

static hemlock
#

That all depends on your server

#

Where and how you are hosting your code

wise swan
#

Well, I'm using firebase cloud functions feature to host all the functions needed to deal with backend.

#

Ok i guess I found out

static hemlock
#

You should be able to see your backend logs in your Cloud Console then

wise swan
#

Yeah, yeah I see actually it. But the structure of the callable functions is that the req.data should be taken instead of req.body.

static hemlock
#

Gotcha

#

This shouldn't have been different in test mode really

#

So I would make sure you test end-to-end in test mode and ensure everything is working there

wise swan
#

Ok, sure but this will require some time.

wise swan
#

Suddenly it does not work as it's supposed either.

#

That's bizzare though.

#

However as I've been using test-mode in order to test all functionalities. It worked flawlessly, now something has been screwed up though.

static hemlock
#

Without more details I can't really help

#

The best thing to do is to add logs in each step of the flow

#

So you can see exactly what is happening

wise swan
static hemlock
#

We can walk through each step together. Did you add the logs I mentioned above?

#

What did that output?

wise swan
#

There was this error, but wait I am likely to finish this error, but I have to speak to other guy in order to ensure myself, ok? TypeError: Cannot read properties of undefined (reading 'accountData')

covert gullBOT
wise swan
#

Ok, guys I finally get the appropriate error, however it sounds I've got finally the response from stripe "You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/." and looking into the stackoverflow, how this issue was commonly solved, was to put the secret key while requiring stripe. But i do it, so perhabs I screw up with configuing dotenv? Let me guys just know. js const path = require("path"); require("dotenv").config({path: path.join(__dirname, "../.env")}); const functions = require("firebase-functions"); const admin = require("firebase-admin"); const {initializeApp} = require("firebase-admin/app"); const express = require("express"); const bodyParser = require("body-parser"); const cors = require("cors"); const app = express(); app.use(bodyParser.urlencoded({extended: true})); initializeApp(); app.use(express.static("./bookfreak-project/public")); app.use(cors({origin: true})); const stripe = require("stripe")(process.env.REACT_APP_STRIPE_SEC_CLIENT); const {increment} = require("firebase/database"); const {Convert} = require("easy-currencies");

barren marlin
#

HI 👋

I"m taking over and catching up

#

However, looking at that error message it suggests to me that this line

const stripe = require("stripe")(process.env.REACT_APP_STRIPE_SEC_CLIENT);

is not initializing the Stripe client with the correct Secret key

wise swan
barren marlin
#

I would recommend reviewing the runtime environment and adding some logging to make sure the correct Secret key is getting loaded

barren marlin
#

As for past discussions, I'm sorry to say I don't clearly remember. On average we help >200 devs per day so it's hard to keep them all straight

wise swan
barren marlin
#

Thanks, I appreciate it

wise swan
#

Ok, so just give me a second I will tell you if the secret key will have been retrieved or not.

#

We've got the response secret key undefined. It looks like the require("dotenv").config(...) is wrong.

barren marlin
#

Okay, so there's where you can start digging.

wise swan
#

Yes, so I'll try to remove this path firstly coz it might cause the issue. At least that's my firs idea that came into my mind. Let us see.

covert gullBOT
#

luftie-missing-apikey