mobile favicon
Services

serverSupabaseClient

Make requests to the Supabase API on server side with the serverSupabaseClient service
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. Be careful, serverSupabaseClient is returning a promise.

server/api/libraries.ts
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:

pages/index.vue
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.

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

Made with Nuxt Studio