nuxt-modules / supabase

Supabase module for Nuxt.
https://supabase.nuxtjs.org
MIT License
680 stars 124 forks source link

how to getSession with serverSupabaseClient? #205

Open stlbucket opened 1 year ago

stlbucket commented 1 year ago

Is there another header I need to provide in order for serverSupabaseClient to find a session?

I have the following server middleware:

import { serverSupabaseClient } from '#supabase/server'

export default eventHandler(async (event) => {
  const client = serverSupabaseClient(event)

  const { data } = await client.auth.refreshSession()
  console.log('headers', event.node.req.headers)
  console.log('CLIENT SESSION', data)
})

my output always looks like this:

headers {                                                                                                                                                6:59:02 PM
  'sec-fetch-site': 'same-origin',
  'sec-fetch-mode': 'cors',
  'sec-fetch-dest': 'empty',
  cookie: 'sb-access-token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjg5NjQ5MDc3LCJzdWIiOiJlZjlmMzM3Yy05N2Y3LTRiOWYtYmI1Zi04ZjRlMWQ2OTY4ZDEiLCJlbWFpbCI6ImFwcC1hZG1pbi1zdXBlckBleGFtcGxlLmNvbSIsInBob25lIjoiIiwiYXBwX21ldGFkYXRhIjp7InByb3ZpZGVyIjoiZW1ha..............truncated',
CLIENT SESSION { user: null, session: null }                                                                                                             6:59:02 PM
...
}

i can manually parse the cookie down the chain.

stlbucket commented 1 year ago

i believe i am simply confused thinking that the cookie just needs to be there, and not each piece of it as a separate header:

https://supabase.nuxtjs.org/usage/services/server-supabase-client

useRequestHeaders(['cookie'])

should fix this for me, yes? i am using the nuxt-graphql-client, so I think this may be my real question:

https://github.com/Diizzayy/nuxt-graphql-client/discussions/343

stlbucket commented 1 year ago

actually no. i was able to add cookie headers to my request (on first call. still maybe a dependency on the other issue):

  'sb-refresh-token': 'OpuhlJ6B.......',
  'sb-access-token': 'eyJhbGciOiJIU........',

still no values being returned for getSession or refreshSession