Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: missing type from SvelteKit and remix package #557

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions packages/remix/src/createSupabaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SupabaseClientOptionsWithoutAuth
} from '@supabase/auth-helpers-shared';
import { SupabaseClient } from '@supabase/supabase-js';
import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types';

/**
* ## Authenticated Supabase client
Expand Down Expand Up @@ -90,7 +91,10 @@ export function createBrowserClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
: string & keyof Database,
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
? Database[SchemaName]
: any
>(
supabaseUrl: string,
supabaseKey: string,
Expand All @@ -101,14 +105,14 @@ export function createBrowserClient<
options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
cookieOptions?: CookieOptionsWithName;
} = {}
): SupabaseClient<Database, SchemaName> {
): SupabaseClient<Database, SchemaName, Schema> {
if (!supabaseUrl || !supabaseKey) {
throw new Error(
'supabaseUrl and supabaseKey are required to create a Supabase client! Find these under `Settings` > `API` in your Supabase dashboard.'
);
}

return createSupabaseClient<Database, SchemaName>(supabaseUrl, supabaseKey, {
return createSupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
...options,
global: {
...options?.global,
Expand Down Expand Up @@ -159,7 +163,10 @@ export function createServerClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
: string & keyof Database,
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
? Database[SchemaName]
: any
>(
supabaseUrl: string,
supabaseKey: string,
Expand All @@ -174,7 +181,7 @@ export function createServerClient<
options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
cookieOptions?: CookieOptionsWithName;
}
): SupabaseClient<Database, SchemaName> {
): SupabaseClient<Database, SchemaName, Schema> {
if (!supabaseUrl || !supabaseKey) {
throw new Error(
'supabaseUrl and supabaseKey are required to create a Supabase client! Find these under `Settings` > `API` in your Supabase dashboard.'
Expand All @@ -187,7 +194,7 @@ export function createServerClient<
);
}

return createSupabaseClient<Database, SchemaName>(supabaseUrl, supabaseKey, {
return createSupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
...options,
global: {
...options?.global,
Expand Down
8 changes: 6 additions & 2 deletions packages/shared/src/createClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { createClient } from '@supabase/supabase-js';
import { SupabaseClientOptionsWithoutAuth } from './types';
import { isBrowser } from './utils';
import { StorageAdapter } from './cookieAuthStorageAdapter';
import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types';

export function createSupabaseClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
: string & keyof Database,
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
? Database[SchemaName]
: any
>(
supabaseUrl: string,
supabaseKey: string,
Expand All @@ -20,7 +24,7 @@ export function createSupabaseClient<
) {
const bowser = isBrowser();

return createClient(supabaseUrl, supabaseKey, {
return createClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
...options,
auth: {
flowType: 'pkce',
Expand Down
12 changes: 8 additions & 4 deletions packages/sveltekit/src/supabaseLoadClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { Session, SupabaseClient } from '@supabase/supabase-js';
import { LoadEvent } from '@sveltejs/kit';
import { SvelteKitLoadAuthStorageAdapter } from './loadStorageAdapter';
import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types';

let cachedBrowserClient: SupabaseClient<any, string> | undefined;

Expand Down Expand Up @@ -52,7 +53,10 @@ export function createSupabaseLoadClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
: string & keyof Database,
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
? Database[SchemaName]
: any
>({
supabaseUrl,
supabaseKey,
Expand All @@ -73,13 +77,13 @@ export function createSupabaseLoadClient<
serverSession: Session | null;
options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
cookieOptions?: CookieOptionsWithName;
}): SupabaseClient<Database, SchemaName> {
}): SupabaseClient<Database, SchemaName, Schema> {
const browser = isBrowser();
if (browser && cachedBrowserClient) {
return cachedBrowserClient as SupabaseClient<Database, SchemaName>;
return cachedBrowserClient as SupabaseClient<Database, SchemaName, Schema>;
}

const client = createSupabaseClient<Database, SchemaName>(supabaseUrl, supabaseKey, {
const client = createSupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
...options,
global: {
fetch: event.fetch,
Expand Down
11 changes: 8 additions & 3 deletions packages/sveltekit/src/supabaseServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
} from '@supabase/auth-helpers-shared';
import { RequestEvent } from '@sveltejs/kit';
import { SvelteKitServerAuthStorageAdapter } from './serverStorageAdapter';
import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types';
import { SupabaseClient } from '@supabase/supabase-js';

/**
* ## Authenticated Supabase client
Expand Down Expand Up @@ -61,7 +63,10 @@ export function createSupabaseServerClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
: string & keyof Database,
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
? Database[SchemaName]
: any
>({
supabaseUrl,
supabaseKey,
Expand All @@ -76,8 +81,8 @@ export function createSupabaseServerClient<
options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
cookieOptions?: CookieOptionsWithName;
expiryMargin?: number;
}) {
const client = createSupabaseClient<Database, SchemaName>(supabaseUrl, supabaseKey, {
}): SupabaseClient<Database, SchemaName, Schema> {
const client = createSupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
...options,
global: {
...options?.global,
Expand Down