serverSupabaseUser


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

This function is working similary as the useSupabaseUser composable but is designed to be used in server routes.

Define your server route and import the serverSupabaseUser from #supabase/server.

server/api/me.ts
import { serverSupabaseUser } from '#supabase/server'export default defineEventHandler(async (event) => {  return await serverSupabaseUser(event)})

Then call your api route from any vue file:

pages/index.vue
const user = ref(null)const fetchMe = async () => {   user.value = await $fetch('/api/me')}

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 user = ref(null)const { data } = await useFetch('/api/me', {  headers: useRequestHeaders(['cookie'])})user.value = data