This function is similar to the useSupabaseSession composable but is used in server routes.
serverSupabaseSession is considered unsafe, since the session comes from the client and users can tamper with it. For checking if the user is logged in, always use serverSupabaseUserDefine your server route and import the serverSupabaseSession from #supabase/server.
import { serverSupabaseSession } from '#supabase/server'
export default defineEventHandler(async (event) => {
return await serverSupabaseSession(event)
})
Then call your api route from any vue file:
const session = ref(null)
const fetchSession = async () => {
session.value = await $fetch('/api/session')
}
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 session = ref(null)
const { data } = await useFetch('/api/session', {
headers: useRequestHeaders(['cookie'])
})
session.value = data