diff --git a/src/module.ts b/src/module.ts index 9d6a6381f..231650de8 100644 --- a/src/module.ts +++ b/src/module.ts @@ -183,6 +183,7 @@ export default defineNuxtModule({ inline: [resolve('./runtime')], }) nitroConfig.alias['#supabase/server'] = resolveRuntimeModule('./server/services') + nitroConfig.alias['#supabase/database'] = resolve(nitroConfig.buildDir!, 'types/supabase-database') }) addTemplate({ diff --git a/src/runtime/server/services/serverSupabaseClient.ts b/src/runtime/server/services/serverSupabaseClient.ts index 62e708bd7..8863d5876 100644 --- a/src/runtime/server/services/serverSupabaseClient.ts +++ b/src/runtime/server/services/serverSupabaseClient.ts @@ -3,9 +3,10 @@ import { createServerClient, parseCookieHeader, type CookieOptions } from '@supa import { getHeader, setCookie, type H3Event } from 'h3' import { fetchWithRetry } from '../../utils/fetch-retry' import { useRuntimeConfig } from '#imports' -import type { Database } from '#build/types/supabase-database' +// @ts-expect-error - `#supabase/database` is a runtime alias +import type { Database } from '#supabase/database' -export const serverSupabaseClient = async (event: H3Event): Promise> => { +export const serverSupabaseClient: (event: H3Event) => Promise> = async (event: H3Event) => { // No need to recreate client if exists in request context if (!event.context._supabaseClient) { // get settings from runtime config @@ -38,5 +39,5 @@ export const serverSupabaseClient = async (event: H3Event): Promis }) } - return event.context._supabaseClient + return event.context._supabaseClient as SupabaseClient } diff --git a/src/runtime/server/services/serverSupabaseServiceRole.ts b/src/runtime/server/services/serverSupabaseServiceRole.ts index 9e14c6ad8..d30e433c5 100644 --- a/src/runtime/server/services/serverSupabaseServiceRole.ts +++ b/src/runtime/server/services/serverSupabaseServiceRole.ts @@ -2,9 +2,10 @@ import type { SupabaseClient } from '@supabase/supabase-js' import { createClient } from '@supabase/supabase-js' import type { H3Event } from 'h3' import { useRuntimeConfig } from '#imports' -import type { Database } from '#build/types/supabase-database' +// @ts-expect-error - `#supabase/database` is a runtime alias +import type { Database } from '#supabase/database' -export const serverSupabaseServiceRole = (event: H3Event): SupabaseClient => { +export const serverSupabaseServiceRole: (event: H3Event) => SupabaseClient = (event: H3Event) => { const { supabase: { serviceKey }, public: {