hey, im trying to fetch data based on the auth.use...
# help
a
hey, im trying to fetch data based on the auth.user.id via svelte endpoint but im getting a little trouble on how i should call. the 'event' table has coloum named "user_id" that is linked to the auth.user.id table
Copy code
import supabase from '$lib/db';

export const get = async () => {
    try {
        const { data: events, error } = await supabase
            .from('event')
            .select('*')
            .eq('user_id', auth.users.id));

        if (error) throw error;

        return {
            body: {
                events
            }
        };
    } catch (e) {
        console.log({ e });
    }
};
n
Hello @Ape R Us! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
a
my user is in a store file so im not sure how to pull it out to be able to use it 😦
t
I think you want to use
const user = supabase.auth.user()
as per the sample below. This is from the supabase svelte tutorial I completed about 6 months ago. I don't think anything has changed.
Copy code
js

  async function getProfile() {
    try {
      loading = true
      const user = supabase.auth.user()
      email = user.email
  
      let { data, error, status } = await supabase
        .from('profiles')
        .select(`username, website, avatar_url`)
        .eq('id', user.id)
        .single()

      if (error && status !== 406) throw error

      if (data) {
        username = data.username
        website = data.website
        avatar_url = data.avatar_url
      }
    } catch (error) {
      alert(error.message)
    } finally {
      loading = false
    }
}
n
Ape R Us (2022-04-13)
a
yea, still getting the error, maybe it cant work with endpoints
t
> endpoints > Is this the same as the Serverless Edge Functions implemented with Deno?