The clerk encountered difficulty retrieving the publishable key from the environment variables within Next.js version 13

I recently developed a website using Next 13 (an experimental app directory) and integrated authentication with Clerk.

While everything runs smoothly on my local environment, once deployed to Netlify, the site fails to load. Upon checking the console, I encountered the following error:

@clerk/nextjs: Missing publishableKey. You can obtain your key from https://dashboard.clerk.com/last-active?path=api-keys.
    at Object.throwMissingPublishableKeyError

The publishable key is already added to my environment variables in Netlify under

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
. Just to be safe, I also included it under CLERK_PUBLISHABLE_KEY.

Moreover, should the key be automatically received by some clerk code? Because I haven't utilized that variable in my code and the documentation doesn't mention its necessity.

Answer №1

Facing a similar issue, I found the solution by simply updating the ClerkProvider declaration file with the necessary publishable key.

function UpdateProviders({ children, pageProps }) {
    return (
            <ClerkProvider {...pageProps} publishableKey={process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY}>
              {children}
            </ClerkProvider>

    )
}

export default UpdateProviders

Answer №2

  1. It is important to include the clerk key and secret in your project secrets for security purposes

https://github.com/{username}/{project}/settings/secrets/actions

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=********************
CLERK_SECRET_KEY=***************
  1. When setting up GitHub workflow, make sure to load the environment variables required for the job

Especially when running yarn run build, ensure that you add these variables to the build step like this

      - run: yarn install && yarn run build
        env:
          NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: "${{secrets.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY}}"
          CLERK_SECRET_KEY: "${{secrets.CLERK_SECRET_KEY}}"

Answer №3

Visit the page where the ClerkProvider is declared and insert the publishable key within the appropriate tag

To modify the RootLayout function with your publishable key, follow this code snippet:

export default function RootLayout( { children }: { children : React.ReactNode}) { return ( <ClerkProvider publishableKey={'YOUR PUBLISHABLE KEY GOES HERE'}> <body className={${inter.className} bg-dark-1}> {children} ) }

Answer №4

Resolved the issue by relocating .env.local to the main folder of the project.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on Implementing Link href in Next.js v12

When I set the href as a string, the link functions properly. However, when I use an object for the href, the link fails to work. Despite seeing the correct querystring when hovering over the link, it always takes me back to the first page. // ProdCard t ...

Is it necessary for me to utilize Parallel Routes in Nextjs 13?

Hello everyone, I've recently delved into the world of Next.js version 13 and I have a question that's been boggling my mind. According to the documentation, Next.js is used for displaying one or more pages within the same layout. But can't ...

tips for accessing the useState value once it has been initialized

When using the state hook in my code, I have: const [features, setFeatures] = useState([]) const [medicalProblem, setMedicalProblem] = useState([]) The medicalProblem variable will be initially populated with a response from an API call: useEf ...

What is the best way to retrieve data in my client component without risking exposing my API key to unauthorized users?

To retrieve information, I plan to use pagination in order to specify a particular page number within the API URL and fetch additional data by updating the value of page. The process of fetching data in my server component is as follows: // fetchData.tsx ...

FixedSizeGrid does not activate the loadMoreItems function within the InfiniteLoader component in react-window

Hey there! I'm diving into the world of React JS and looking to create a dynamic product list using react-window. I've got the hang of implementing a fixed-size list with InfiniteLoader, which allows me to successfully make API calls and add new ...

What is causing the ESLint error when trying to use an async function that returns a Promise?

In my Next.js application, I have defined an async function with Promise return and used it as an event handler for an HTML anchor element. However, when I try to run my code, ESLint throws the following error: "Promise-returning function provided t ...

What are some ways to leverage props in React to avoid unnecessary duplication?

How can I utilize props to avoid this repetition in my code?? import React from "react"; export const FindUs = () => { return ( <div className="p-[6%]"> <div className="text-landing-title font-semibold text-4xl "> ...

"Encountered an error of 'Authentication failed' while trying to access a blob using the SAS

My team and I are currently in the process of developing a NextJS web app, and we have recently integrated Azure Blob Storage for file upload and display. I am tasked with working on displaying images on the frontend. To achieve this, I am using the genera ...

React and Next.js issues with "Window is not defined" errors

Currently working with React Hooks and NextJS, I am in the process of creating a Navbar along with its functionality. However, upon refreshing the page, an error appears that was not present when I was using this code in my previous React project. If anyo ...

Utilizing URL-based conditions in Reactjs

Currently, I am working with Reactjs and utilizing the Next.js framework. My goal is to display different text depending on whether the URL contains "?id=pinned". How can I achieve this? Below is the snippet of my code located in [slug.js] return( ...

What is the process for obtaining a client-side cookie using next.js?

I'm currently facing an issue where I can't seem to maintain a constant value for the isAuthenticated variable between server-side and client-side in next.js. In my setup, I am using a custom app.js file to wrap the app with Apollo Provider. The ...

What steps should I take to ensure my API secret remains secure during my next.js deployment?

Recently, I created a small internal application using React and Next.js. To keep my API key and secret secure, I followed the instructions on how to use an .env file provided by Next.js. In my api/hello.js file, I have a simple request that looks like th ...

Develop an integration of NextJS with .Net Core framework

Looking to develop a solution that integrates NextJS on the frontend and .NET6 on the backend within one unified setup for hosting on IIS10. While exploring Visual Studio 2022, I noticed a React template but encountered issues when trying to transition to ...

The true nature of Next.js Server action is revealed - it actually returns a promise instead

After updating my Next.js version to 14.1.4, I encountered an issue in a client component when calling checkoutWithStripe. The return type of getURL has changed from a String to a Promise in this new version. I'm not sure why this change occurred as ...

Troubleshooting: Next.js 13 custom 404 page not functioning as expected

Currently, I am experimenting with setting up a custom 404 page for my next 13 project. I am following this approach: https://nextjs.org/docs/app/api-reference/file-conventions/not-found. However, whenever I enter an unmatched URL, the page appears blank! ...

Is there a way to end my session in nextAuth on NextJS 14?

Recently, I've started using Typscript with a NextJS14 project that utilizes NextAuth for authentication. While there weren't any errors in the JavaScript version of my code, I encountered an error when working with TypeScript. This is a snippet ...

Develop a higher-order authentication component for securing routes in Next.js

Currently, I am developing the authentication system for my Next.js application. I have set up a /api/auth/login endpoint to handle user login requests. Upon successful validation of user data, I generate an HTTP-only cookie containing a JWT token and send ...

Unable to authenticate the initial certificate with Node

Out of the blue, my Node environments are experiencing issues with installing packages and freezing at idealTree:my-app : sill idealTree buildDeps Although I attempted to fix it by using npm config set registry http://registry.npmjs.org/ --global, it didn ...

Tips for avoid having the router.asPath useEffect triggered twice on initial load in a NextJs application when using getServerSideProps

I am in the process of creating an exploration page that utilizes URL query parameters (utilizing NextJs pages with getServerSideProps). When an external user visits the URL domain.com/explore?type=actions&category=food, it will retrieve data for "act ...

What happens if ChainId is not defined in the OpenSea 2.0 clone created with Next.js, Replit, thirdweb, and tailwind CSS?

Recently, I came across a tutorial on YouTube that caught my attention. It's about creating an Open Sea 2.0 clone with Next.js, Replit, thirdweb, Infura, and Tailwind CSS. The video used Rinkeby Network, but since it's not stable anymore, I switc ...