-
Notifications
You must be signed in to change notification settings - Fork 155
Description
In nuxt-supabase v2.0.0 with Nuxt 4.1.2, serverSupabaseClient is returning any type on the client-side instead of the proper inferred types from the generated Database types. This happens even though the Supabase config specifies the types path, and the documentation claims auto-discovery.
However, explicitly adding <Database> to serverSupabaseClient<Database>() fixes it. Why is the generic type not auto-discovered as per the docs?
To Reproduce
- Set up a Nuxt 4.1.2 project with nuxt-supabase v2.0.0.
- Configure Supabase in
nuxt.config.ts:supabase: { types: '~~/types/database.types.ts' } - Create a server route like this (e.g.,
server/api/test.post.ts):import { useValidatedBody, z } from 'h3-zod' import { serverSupabaseClient, serverSupabaseUser } from '#supabase/server' export default defineEventHandler(async (event) => { const user = await serverSupabaseUser(event) if (!user) { throw createError({ statusCode: 401, statusMessage: 'Unauthorized' }) } const body = await useValidatedBody(event, z.object({ ... })) const supabase = await serverSupabaseClient(event) // Calculate total amount const totalAmount = body.items.reduce((total: number, item: { qty: number, price: number }) => { return total + (item.qty * item.price) }, 0) // Insert to Supabase const { data, error } = await supabase .schema('finance') .from('budgets') .insert({ title: body.title, total_amount: totalAmount, ... }) .select() .single() if (error) { throw createError({ statusCode: 500, statusMessage: error.message || 'Failed to create budget planning' }) } return data })
- Call this route from the client-side using
useFetchor$fetch. - Observe the return type in your IDE or TypeScript checker:
FetchResult<'/api/test', 'POST'>returnsanyinstead of the expected infering query result.
Expected behavior
The client-side should infer the correct Database types (e.g., from database.types.ts) without needing to explicitly specify <Database>. As per the docs: "The database definitions will be automatically passed to all clients: useSupabaseClient, serverSupabaseClient and serverSupabaseServiceRole."
Actual behavior
- Without
<Database>, the return type isany. - With
serverSupabaseClient<Database>(), it works correctly. - When returning a simple string like
'test', the type is correctly inferred asstring.
Screenshots
Environment
- Nuxt version: 4.1.2
- nuxt-supabase version: 2.0.0
- Node.js version: v23.9.0
- Operating System: macOS
Additional context
This seems like a TypeScript inference issue in the module. The workaround is to manually add <Database>, but it should be automatic as documented.

