0

I'm trying to connect supabase to sveltekit, but I got an Error 500. I have the API key but it's in my .env file. I think, the env didn't read.

//supabaseclient.js

import { createClient } from '@supabase/supabase-js'
import { SUPABASE_KEY } from "$env/static/private"

const supabaseUrl = 'https://eymqprbapxasydwjnhfc.supabase.co'
const supabaseKey = SUPABASE_KEY;

export const supabase = createClient(supabaseUrl, supabaseKey)

+page.server.js


import { supabase } from "$lib/supabaseClient";

export async function load() {
const { data } = await supabase.from("countries").select();
return {
countries: data ?? \[\],
};
}

+page.svelte

<script>
    export let data;
</script>

<ul>
    {#each data.countries as country}
        <li>{country.name}</li>
    {/each}
</ul>

Is there an another way to read the env file? Or there something's wrong on my code?

  1. I tried to put "meta.env..." but it doesn't work

  2. I tried to put the Actual API Key. It works, but there's no output

0 Answers0