N
Nuxt7mo ago
Menttis

Server middleware secure with Nuxt/Supabase module

Hello, I'm trying to secure Nuxt server API route with middleware, using Nuxt/Supabase module. I have Supabase setup to use roles (RBAC), the goal is to have the JWT decoded from the session. This is working fine on the client side and in Pinia store with jwt-decode. For some reason the serverSupabaseUser and serverSupabaseSession returns empty. So I can't access the data. The user is logged in and I can see the user object just fine on the client side. Any ideas why this the user and session logs empty with code below?
import { serverSupabaseClient } from '#supabase/server'
import { serverSupabaseUser } from '#supabase/server'
import { serverSupabaseSession } from '#supabase/server'

export default defineEventHandler(async (event) => {
const supabase = await serverSupabaseClient(event);
const user = await serverSupabaseUser(event)
const session = await serverSupabaseSession(event)

console.log('USER ' + JSON.stringify(user)) // Returns empty object, or null if no .stringify
console.log('SESSION' + JSON.stringify(session)); // Returns empty object, or null if no .stringify

})
import { serverSupabaseClient } from '#supabase/server'
import { serverSupabaseUser } from '#supabase/server'
import { serverSupabaseSession } from '#supabase/server'

export default defineEventHandler(async (event) => {
const supabase = await serverSupabaseClient(event);
const user = await serverSupabaseUser(event)
const session = await serverSupabaseSession(event)

console.log('USER ' + JSON.stringify(user)) // Returns empty object, or null if no .stringify
console.log('SESSION' + JSON.stringify(session)); // Returns empty object, or null if no .stringify

})
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server