Error when Using 'Use Client' in Next 13 App folder
I have a project where I'm using the Next13 app folder. I tried putting all my APIs inside the app/api folder, but when I tried to call the api in the pages where I want to use them, I get
"Error: You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass
enableBrowser: true
to the client options to remove this error."
If I'm not using "Use client" it works.2 Replies
Sounds like you're making the xata calls inside client components rather than api routes. You don't want to do this, because it exposes your API key over the browser.
essentially, you want to make api calls against xata in your api routes or your server components, and not your client components.
you should check out our sample gallery app for an example of how this is done. https://github.com/xataio/sample-nextjs-chakra-gallery-app
GitHub
GitHub - xataio/sample-nextjs-chakra-gallery-app: Gallery applicati...
Gallery application built with Xata, Next.js and Chakra UI - GitHub - xataio/sample-nextjs-chakra-gallery-app: Gallery application built with Xata, Next.js and Chakra UI