supabase / ssr

Supabase clients for use in server-side rendering frameworks.
MIT License
81 stars 7 forks source link

Error when creating a Supabase server client with the Quasar Framework #79

Open cvillagrasa opened 3 weeks ago

cvillagrasa commented 3 weeks ago

Bug report

Describe the bug

I'm getting an error on line https://github.com/supabase/ssr/blob/549fe62813fb9c7277f7eda9e46ee0420f8e0b5f/src/cookies.ts#L190 when creating a Supabase server client on the Quasar Framework:

.../node_modules/@supabase/ssr/dist/main/cookies.js:238
    cookie = allCookies?.find(({ name }) => name === chunkName) || null;
                                               ^

TypeError: allCookies?.find is not a function

IMPORTANT: The error is solved if adding an additional optional chaining operator to the supabase source, as in allCookies?.find?.(. Not sure if there's any underlying issue, though.

To Reproduce

This is how I'm creating the client:

import { Cookies } from 'quasar';
import { QSsrContext } from '@quasar/app-vite';
import { createServerClient, type CookieOptions } from '@supabase/ssr';

function initSupabaseServer(ssrContext: QSsrContext) {
  const cookies = Cookies.parseSSR(ssrContext)
  return createServerClient(
    process.env.VITE_SUPABASE_URL!,
    process.env.VITE_SUPABASE_ANON_KEY!,
    {
      cookies: {
        getAll: () => cookies?.getAll(),
        setAll: (cookiesToSet: {
          name: string
          value: string
          options: CookieOptions
        }[]) => {
          cookiesToSet.forEach(({ name, value, options }) =>
            cookies.set(name ,value, options)
          )
        }
      }
    }
  )
}

The Cookies.parseSSR bit is in accordance with Quasar SSR instructions.

Screenshots

image

System information

Additional context

This error happens both during development with Vite, and in production when running Node.js