supabase/supabase-js

Weird type errors with 2.56.0

Closed this issue Β· 23 comments

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I get the following error when using 2.56.0. Same code build with no errors on 2.55.0. I have my types setup correctly too.

Type error: Property 'onboarded' does not exist on type 'never'.

To Reproduce

  • generate types
  • use supabase SSR with Nextjs.
  • use SSR client with cookies and everything
  • select

Example code

    const {
        data: { user },
    } = await supabase.auth.getUser()

    if (user?.id) {
        const { data: profile } = await supabase
            .from('profiles')
            .select('onboarded')
            .eq('id', user.id)
            .single()

        if (profile?.onboarded === true) {
            redirect('/dashboard')
        } else {
            redirect('/onboarding')
        }
    }

Expected behavior

Should build.

System information

  • Nextjs 15
  • pnpm

Facing the same issue. For now i have downgraded to [2.55.0] an it works.

I had the same issue, downgrading fixed it for now.

Can you try upgrading @supabase/ssr?

Also, can you share an example repo where we can reproduce the issue?

Same problem. I think problem is from this #1537. I get error with event.locals.supabase = createServerClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY,...
in Sveltekit

Same problem happened here when upgrading @supabase/supabase-js from 2.55 to 2.56

But force upgrading @supabase/ssr to 0.7.0 solved it, thanks πŸ‘

I get similar but just as disruptive errors. I have to avoid 2.56 and 2.57. will pin to 2.55 for a while.

@geoguide does @xavier-ayme 's solution work for you? force-upgrade @supabase/ssr to 0.7.0?

0.7.0. didnt help but this help
createServerClient<Database, 'public'>

Thanks a lot, @xavier-ayme. You are a saviour, man.

@geoguide does @xavier-ayme 's solution work for you? force-upgrade @supabase/ssr to 0.7.0?

No it doesn't fix it for me. and either does changing that typing on create client. I usually get my type for client from TypedSupabaseClient

It looks like it's only on updates and might be that supabase-cache-helpers hasn't been updated for the new versions?

might be that supabase-cache-helpers hasn't been updated for the new versions?

That might be it - we’ll work with the maintainer to get this updated πŸ‘

Curious why supabase doesn't work with the maintainer to support this library, it seems like he's always caught off guard with changes and this library is amazing for people using supabase.

might be that supabase-cache-helpers hasn't been updated for the new versions?

That might be it - we’ll work with the maintainer to get this updated πŸ‘

Also thank you!

Thank you!

New Supabase Cache Helpers version (v0.2.3+) has been released that’s compatible with v2.56.0+. Please give it a try if you’re using an older version of the cache helpers πŸ™

It works for me but I still have to manually type the createServerClient or else I get weird errors there

return createServerClient<Database, 'public'>

No big deal - happy to do so but wondering why it inferred correctly before. Is it because the types got more strict and so if i do a db.schema = 'other_schema' or something i'll get better type support? Thanks again for the quick fix!

Does it show errors if you just do createServerClient() without supplying types?

If you don't supply the schema (second type argument) then it assumes the public schema, which won't work if you're querying other schemas.

Does it show errors if you just do createServerClient() without supplying types?

If you don't supply the schema (second type argument) then it assumes the public schema, which won't work if you're querying other schemas.

Yes it shows errors if i don't supply types. I'm using public schema.

Type 'SupabaseClient<Database, "public" | "graphql_public" | "storage", "public" | "graphql_public" | "storage", { Tables: { addresses: { Row: { address_type: "home" | "company"; city: string | null; ... 9 more ...; updated_at: string | null; }; Insert: { ...; }; Update: { ...; }; Relationships: [...]; }; ... 45 more ...;...' is not assignable to type 'TypedSupabaseClient'.
  Type '"public" | "graphql_public" | "storage"' is not assignable to type '"public"'.
    Type '"graphql_public"' is not assignable to type '"public"'.ts(2322)

Reference here's my code:

'use server'
import { cookies } from 'next/headers'
import type { TypedSupabaseClient } from '@/lib/supabase.types'
import type { CookieOptions } from '@supabase/ssr'
import { createServerClient } from '@supabase/ssr'

export async function getSupabaseServer(): Promise<TypedSupabaseClient> {
	const cookieStore = await cookies()
	return createServerClient(
		process.env.NEXT_PUBLIC_SUPABASE_URL || '',
		process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || '',
		{
			auth: {
				persistSession: true,
			},
			cookies: {
				getAll() {
					return cookieStore.getAll()
				},
				setAll(cookiesToSet: { name: string; value: string; options: CookieOptions }[]) {
					try {
						cookiesToSet.forEach(({ name, value, options }) => {
							cookieStore.set(name, value, options)
						})
					} catch {
						// The `setAll` method was called from a Server Component.
						// This can be ignored if you have middleware refreshing
						// user sessions.
					}
				},
			},
			cookieOptions: {
				maxAge: 60 * 60 * 24 * 7,
			},
		},
	)
}

Can you share TypedSupabaseClient?

import type { SupabaseClient } from '@supabase/supabase-js'
import type { Database } from '@/types/database.types'

export type TypedSupabaseClient = SupabaseClient<Database>

edit wait maybe i just have to add the public there.

edit2: no still errors

It should work if you do:

import type { SupabaseClient } from '@supabase/supabase-js'
import type { Database } from '@/types/database.types'

export type TypedSupabaseClient = SupabaseClient<Database>
'use server'
import { cookies } from 'next/headers'
import type { TypedSupabaseClient } from '@/lib/supabase.types'
import type { CookieOptions } from '@supabase/ssr'
import { createServerClient } from '@supabase/ssr'

export async function getSupabaseServer(): Promise<TypedSupabaseClient> {
	const cookieStore = await cookies()
	return createServerClient<Database>(
		process.env.NEXT_PUBLIC_SUPABASE_URL || '',
		process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || '',
		{
			auth: {
				persistSession: true,
			},
			cookies: {
				getAll() {
					return cookieStore.getAll()
				},
				setAll(cookiesToSet: { name: string; value: string; options: CookieOptions }[]) {
					try {
						cookiesToSet.forEach(({ name, value, options }) => {
							cookieStore.set(name, value, options)
						})
					} catch {
						// The `setAll` method was called from a Server Component.
						// This can be ignored if you have middleware refreshing
						// user sessions.
					}
				},
			},
			cookieOptions: {
				maxAge: 60 * 60 * 24 * 7,
			},
		},
	)
}

If you're supplying Database in TypedSupabaseClient, it needs to be matched in the createServerClient call

That seems to work and makes sense. thank you!

I think we've closed the loop here - if you're still facing this issue and the suggested fixes above doesn't help, please open another issue. Thanks!