#luftie-missing-apikey
1 messages · Page 1 of 1 (latest)
Yes sure, givw me only a moment I am AFK.
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};
}
}); ```
Where do you see an empty object exactly?
You aren't logging the object anywhere in that code?
The empty object is logged from the frontend side as I call the functions.
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
All right, I suspect that it won't be visible in the developer console, but at least we can give it a try, ok.
Yeah you would need to look at your backend logs for that
It won't be in your web dev console
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.
Well, I'm using firebase cloud functions feature to host all the functions needed to deal with backend.
Ok i guess I found out
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.
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
Ok, sure but this will require some time.
So would I expect either.
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.
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
I do understand, what details exactly would you like to have though? Because you know I can start describing the entire process how I do want to log the user to my app, but it would be strenvous to listen to for you i guess.
We can walk through each step together. Did you add the logs I mentioned above?
What did that output?
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')
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");
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
Hi, btw, do you remember last time as quarreled about something what was in the docs ? And we both haven driven ourselfs around the twist? I do apologize for that moment.
I would recommend reviewing the runtime environment and adding some logging to make sure the correct Secret key is getting loaded
Ok, surely.
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
Ok, ok. But nevertheless I wanted to apologize eventhough.
Thanks, I appreciate it
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.
Okay, so there's where you can start digging.
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.
luftie-missing-apikey