serverSupabaseClient


This section assumes you're familiar with Nitro, the server engine powered by Nuxt.

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.

server/api/libraries.ts
import { serverSupabaseClient } from '#supabase/server'export default eventHandler(async (event) => {  const client = serverSupabaseClient(event)  const { data } = await client.from('librairies').select()  return { librairies: data }})

Then call your API route from any vue file:

pages/index.vue
const fetchLibrairy = async () => {  const { librairies } = await $fetch('/api/librairies')}

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.

pages/index.vue
const { data: { librairies }} = await useFetch('/api/librairies', {  headers: useRequestHeaders(['cookie'])})