Not able to use environmental variables in Jotai

87 Views Asked by At

I would like to get data from a CMS and store it globally using Jotai. But I keep getting

Uncaught TypeError: Expected parameter accessToken

When I try to use environmental variables.

At the same time, I don't have this error when I use my token directly. I am also fine using the env variables outside Jotai

My code is

import { createClient } from "contentful";

const client = createClient({
   space: process.env.CONTENTFUL_SPACE_ID!,
   accessToken: process.env.CONTENTFUL_ACCESS_KEY!,
})

export const asyncAtom = atom(async () => {
   const res = await client.getEntries<ILocations>({
      content_type: "locations"
   })

   return res.items
})

export const loadableAtom = loadable(asyncAtom)

While this works fine

const client = createClient({
   space: 'blahblah',
   accessToken: 'blahblahblah',
})
0

There are 0 best solutions below