#szy_api-authentication

1 messages ¡ Page 1 of 1 (latest)

light atlasBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1240249391848230934

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

steady agate
#

const apiKey = process.env.STRIPE_SECRET_KEY
url is: https://api.stripe.com/v1/plans
Before, when i had apiKey set to NEXT_PUBLISHABLE_STRIPE_KEY I was getting GET log in my stripe dashboard but when changed to secret (what stripe told me to) it doesnt receive anything anymore.

silk kraken
#

Hmm, probably isn't a log actually

#

I'd say based on the error your process.env.STRIPE_SECRET_KEY is not what you expect it to be. Can you log it out to confirm?

light atlasBOT
#

szy_api-authentication

steady agate
#

true, it's returning undefined. hmm i wonder why

silk kraken
#

Check your .env file and ensure it's set and the variable is named correctly

steady agate
#

yes yes, i checked. i call it the same in other files.

silk kraken
#

Not sure I'm afraid. Hard to say with the context you've shared but suggests some kind of config issue in your Next.js app

steady agate
#

true, need to figure it out first. thanks

silk kraken
#

In reality you shouldn't make making API requests from your client compoents with effects as it'll expose your secret key

#

You likely need a Next.js server action/route handler

steady agate
#

yes, i just figured it out. the key is not accessible to browser. it was working with NEXT_PUBLISHABLE_STRIPE_KEY because this one is available to the browser. im trying with the route now,

#

I'm calling stripe api successfully but in response im not getting anything back.

export async function POST(request: NextRequest) {
  try {
    const { url } = await request.json()

    const response = await fetch(url, {
      headers: {
        Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`
      }
    })

    const data = await response.json()
    return NextResponse.json(data)
  } catch (error) {
    return NextResponse.json(
      { error: 'Error fetching data from Stripe' },
      { status: 500 }
    )
  }
}

silk kraken
#

OK, can you share the req_xxx ID of the request?

steady agate
#

req_IqtOAUzTvNEj0I

silk kraken
#

Related, why are you using Plans?

steady agate
#

I want to assign posts to plans i have in stripe: for example some posts available for plan Basic, some for Premium.

#

in Sanity CMS

#

to have the data synced

silk kraken
#

And how are you creating the Plans in Stripe?

steady agate
#

In product catalog

#

oh wait, i should be calling v1/products

#

right?

#

i changed the url but still not getting anything back.

#

req_OgfRzG1egDuFz1

tulip graniteBOT
silk kraken
#

Hmm, hard for my to validate that as we don't log JSON responses for GET requests like that. Can you add some logging to your code to validate that we return nothing?

mossy star
#

also do you have an example of a product ID prod_xxx that you're expecting to get back?

steady agate
#

i logged the response:

_Response [Response] {
  [Symbol(realm)]: null,
  [Symbol(state)]: {
    aborted: false,
    rangeRequested: false,
    timingAllowPassed: true,
    requestIncludesCredentials: true,
    type: 'default',
    status: 200,
    timingInfo: {
      startTime: 13070552.116292,
      redirectStartTime: 0,
      redirectEndTime: 0,
      postRedirectStartTime: 13070552.116292,
      finalServiceWorkerStartTime: 0,
      finalNetworkResponseStartTime: 0,
      finalNetworkRequestStartTime: 0,
      endTime: 0,
      encodedBodySize: 4571,
      decodedBodySize: 4571,
      finalConnectionTimingInfo: null
    },
    cacheState: '',
    statusText: 'OK',
    headersList: _HeadersList {
      cookies: null,
      [Symbol(headers map)]: [Map],
      [Symbol(headers map sorted)]: null
    },
    urlList: [ URL {} ],
    body: { stream: undefined }
  },
  [Symbol(headers)]: _HeadersList {
    cookies: null,
    [Symbol(headers map)]: Map(21) {
      'server' => [Object],
      'date' => [Object],
      'content-type' => [Object],
      'content-length' => [Object],
      'connection' => [Object],
      'access-control-allow-credentials' => [Object],
      'access-control-allow-methods' => [Object],
      'access-control-allow-origin' => [Object],
      'access-control-expose-headers' => [Object],
      'access-control-max-age' => [Object],
      'cache-control' => [Object],
      'content-security-policy' => [Object],
      'cross-origin-opener-policy-report-only' => [Object],
      'report-to' => [Object],
      'reporting-endpoints' => [Object],
      'request-id' => [Object],
      'stripe-version' => [Object],
      'vary' => [Object],
      'x-content-type-options' => [Object],
      'x-stripe-routing-context-priority-tier' => [Object],
      'strict-transport-security' => [Object]
    },
    [Symbol(headers map sorted)]: null
  }
}
mossy star
steady agate
#

No reason, i didn't think of it. i have stripe node setup in my project. let me try