hey, Im using svelte and supabase im trying to...
# help
a
hey, Im using svelte and supabase im trying to build a ticketing website so on the homepage all the events would show but in the backend i only want the events to show up that is specific to the user id
Copy code
import supabase from '$lib/db';
import { user } from '$lib/stores/auth';
export const get = async () => {
    try {
        const id = user?.id;
        const { data: events, error } = await supabase.from('event').select('*').eq('user_id', id);
        console.log(user);
        if (error) throw error;
        return {
            body: {
                events
            }
        };
    } catch (e) {
        console.log({ e });
    }
};
Im storing the user in a svelte store
Copy code
export const user = writable(null, (set) => {
    set(supabase.auth.user());
    const subscribe = supabase.auth.onAuthStateChange((_, session) => {
        session ? set(session.user) : set(null);
    });
    return () => {
        subscribe.data.unsubscribe();
    };
});
anyone have any ideas how to fix this?
n
Hello @Ape R Us! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! 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
it works with onMount but im not sure if this is secure
s
This looks like a SvelteKit project and not just Svelte. You should be passing the user as a param to the API endpoint you created for your get function (request).
n
Ape R Us (2022-05-31)
a
how exactly to do that
is there a tutorial or a demo code for example
s
It's more SvelteKit based than Supabase based. I will check tomorrow if I have any example projects with this setup.