#If these are public why they are secure?

1 messages · Page 1 of 1 (latest)

tall otter
#

NEXT_PUBLIC_SUPABASE_URL=<your_supabase_project_url>
NEXT_PUBLIC_SUPABASE_ANON_KEY=<your_supabase_anon_key>

with these two keys you can access any supabase feature. But i dont understand these API keys can be shown on client side and somone steal it so why are they secure?

urban treeBOT
#

Hi @tall otter. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The NEXT_PUBLIC_ prefix in Next.js is used for environment variables that will be inlined into the JavaScript sent to the browser. They are public in the sense that they are included in the client-side code and thus can be seen by anyone who inspects the code in the browser.

However, the security of these keys doesn't come from them being secret, but from the permissions associated with them. The NEXT_PUBLIC_SUPABASE_ANON_KEY is an anonymous key, which means it has very limited permissions. It's typically used to perform operations that don't require authentication, like signing up or logging in users. Any operations that require more permissions would need a different key, which should be kept secret.

As for the NEXT_PUBLIC_SUPABASE_URL, it's just the URL of your Supabase project, which doesn't expose any sensitive information by itself.

In general, you should never put sensitive information in NEXT_PUBLIC_ variables, as they will be exposed to the client. If you need to use sensitive keys, you should use server-side functions to interact with the services that require those keys, so the keys never get sent to the client.

Remember, security isn't just about keeping secrets, but also about limiting what can be done with the information that is public. In the case of these NEXT_PUBLIC_ variables, they are designed to be public, but also to be safe to be public.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@muted wing kapa.ai is still learning and improving, please let us know how it did by reacting below

tall otter
#

so how can i connect supabase with just these 2 keys

#

@urban tree so how can i connect supabase with just these 2 keys

urban treeBOT
#

Let me check the knowledge base for you. One moment! :books:

#

To connect to Supabase with these two keys, you can use the createClient function from the @supabase/supabase-js library. Here's an example:

import { createClient } from '@supabase/supabase-js'

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY

const supabase = createClient(supabaseUrl, supabaseAnonKey)

In this code, createClient is a function that takes two arguments: the URL of your Supabase project, and the anonymous key for your project. It returns a supabase object that you can use to interact with your Supabase project.

Remember to replace <your_supabase_project_url> and <your_supabase_anon_key> with your actual Supabase project URL and anonymous key.

Please note that this code should be run in a server-side environment or a function that gets run at build time, like getStaticProps or getServerSideProps. This is because it uses environment variables, which are not available in the browser.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: