-
I am having a hard time replicating the with-apollo example found here in my own code. I started a new NextJS app(code here) and hooked up my own Contentful API source for a Twitter clone app I'm trying to make. It seems to work fine on the index page where I am using Apollo with SSG and initializing the client in getStaticProps. However, when I try on my [username].js page, where I am trying to use Apollo on the client-side only, it doesn't work. The client side usage in the example works on my computer when I tested it, but I can't seem to figure out where my code differs from the example. When I try with my code, it gives me the following error: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For anyone reading this later, the problem was getting the apiLink and apiToken from process.env. By default those variables are not exposed to the client, they're only available to the Node environment. To expose the variable to the client, you need to prefix the variable name with NEXT_PUBLIC_ to make it visible. After making that change, the client side code works as well. |
Beta Was this translation helpful? Give feedback.
For anyone reading this later, the problem was getting the apiLink and apiToken from process.env. By default those variables are not exposed to the client, they're only available to the Node environment. To expose the variable to the client, you need to prefix the variable name with NEXT_PUBLIC_ to make it visible. After making that change, the client side code works as well.