Skip to content

[Bug] serverSupabaseClient returns 'any' type instead of inferred Database types in Nuxt 4.1.2 #535

@rasyidly

Description

@rasyidly

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

  1. Set up a Nuxt 4.1.2 project with nuxt-supabase v2.0.0.
  2. Configure Supabase in nuxt.config.ts:
    supabase: {
      types: '~~/types/database.types.ts'
    }
    
  3. 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
    })
  4. Call this route from the client-side using useFetch or $fetch.
  5. Observe the return type in your IDE or TypeScript checker: FetchResult<'/api/test', 'POST'> returns any instead 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 is any.
  • With serverSupabaseClient<Database>(), it works correctly.
  • When returning a simple string like 'test', the type is correctly inferred as string.

Screenshots

  • Server route code: Server route code
  • Client-side result: Client-side result

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions