This function is working similary as the useSupabaseClient composable but is designed to be used in server routes.
Define your server route and just import the serverSupabaseClient from #supabase/server. Be careful, serverSupabaseClient is returning a promise.
import { serverSupabaseClient } from '#supabase/server'
export default eventHandler(async (event) => {
const client = await serverSupabaseClient(event)
const { data } = await client.from('libraries').select('*')
return { libraries: data }
})
Then call your API route from any vue file:
const fetchLibrary = async () => {
const { libraries } = await $fetch('/api/libraries')
}
Be careful, if you want to call this route on SSR, please read this section, you must send your browser cookies including your supabase token.
const { data: { libraries }} = await useFetch('/api/libraries', {
headers: useRequestHeaders(['cookie'])
})