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

Chore: Implement naming convention for createClient functions #547

Merged
merged 2 commits into from
May 18, 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
5 changes: 5 additions & 0 deletions .changeset/six-eggs-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@supabase/auth-helpers-nextjs': patch
---

[BREAKING CHANGES]: Renamed createBrowserSupabaseClient to createPagesBrowserClient, createServerSupabaseClient to createPagesServerClient and createMiddlewareSupabaseClient to createMiddlewareClient
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
createSupabaseClient
} from '@supabase/auth-helpers-shared';

export function createBrowserSupabaseClient<
export function createClientComponentClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
Expand Down
106 changes: 106 additions & 0 deletions packages/nextjs/src/deprecated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import {
SupabaseClientOptionsWithoutAuth,
CookieOptionsWithName
} from '@supabase/auth-helpers-shared';
import { createPagesBrowserClient } from './pagesBrowserClient';
import { createPagesServerClient } from './pagesServerClient';
import { GetServerSidePropsContext, NextApiRequest, NextApiResponse } from 'next';
import { NextRequest, NextResponse } from 'next/server';
import { createMiddlewareClient } from './middlewareClient';

/**
* @deprecated utilize the `createPagesBrowserClient` function instead
*/
export function createBrowserSupabaseClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
>({
supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL,
supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
options,
cookieOptions
}: {
supabaseUrl?: string;
supabaseKey?: string;
options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
cookieOptions?: CookieOptionsWithName;
} = {}) {
console.warn(
'Please utilize the `createPagesBrowserClient` function instead of the deprecated `createBrowserSupabaseClient` function.'
);
return createPagesBrowserClient<Database, SchemaName>({
supabaseUrl,
supabaseKey,
options,
cookieOptions
});
}

/**
* @deprecated utilize the `createPagesServerClient` function instead
*/
export function createServerSupabaseClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
>(
context: GetServerSidePropsContext | { req: NextApiRequest; res: NextApiResponse },
{
supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL,
supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
options,
cookieOptions
}: {
supabaseUrl?: string;
supabaseKey?: string;
options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
cookieOptions?: CookieOptionsWithName;
} = {}
) {
console.warn(
'Please utilize the `createPagesServerClient` function instead of the deprecated `createServerSupabaseClient` function.'
);
return createPagesServerClient<Database, SchemaName>(context, {
supabaseUrl,
supabaseKey,
options,
cookieOptions
});
}

/**
* @deprecated utilize the `createMiddlewareClient` function instead
*/
export function createMiddlewareSupabaseClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
>(
context: { req: NextRequest; res: NextResponse },
{
supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL,
supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
options,
cookieOptions
}: {
supabaseUrl?: string;
supabaseKey?: string;
options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
cookieOptions?: CookieOptionsWithName;
} = {}
) {
console.warn(
'Please utilize the `createMiddlewareClient function instead of the deprecated `createMiddlewareSupabaseClient` function.'
);

return createMiddlewareClient<Database, SchemaName>(context, {
supabaseUrl,
supabaseKey,
options,
cookieOptions
});
}
20 changes: 14 additions & 6 deletions packages/nextjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ export type WritableRequestCookies = ReadonlyRequestCookies & {
set: (name: string, value: string, options?: CookieOptions) => void;
};

export { createBrowserSupabaseClient } from './browserClient';
export { createServerSupabaseClient } from './serverClient';
export { createMiddlewareSupabaseClient } from './middlewareClient';
export { createServerComponentSupabaseClient } from './serverComponentClient';
export { createRouteHandlerSupabaseClient } from './routeHandlerClient';
export { createServerActionSupabaseClient } from './serverActionClient';
export { createPagesBrowserClient } from './pagesBrowserClient';
export { createPagesServerClient } from './pagesServerClient';
export { createMiddlewareClient } from './middlewareClient';
export { createClientComponentClient } from './clientComponentClient';
export { createServerComponentClient } from './serverComponentClient';
export { createRouteHandlerClient } from './routeHandlerClient';
export { createServerActionClient } from './serverActionClient';

// Deprecated Functions
export {
createBrowserSupabaseClient,
createServerSupabaseClient,
createMiddlewareSupabaseClient
} from './deprecated';
2 changes: 1 addition & 1 deletion packages/nextjs/src/middlewareClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class NextMiddlewareAuthStorageAdapter extends CookieAuthStorageAdapter {
}
}

export function createMiddlewareSupabaseClient<
export function createMiddlewareClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
Expand Down
3 changes: 3 additions & 0 deletions packages/nextjs/src/pagesBrowserClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createClientComponentClient } from './clientComponentClient';

export const createPagesBrowserClient = createClientComponentClient;
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class NextServerAuthStorageAdapter extends CookieAuthStorageAdapter {
}
}

export function createServerSupabaseClient<
export function createPagesServerClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/routeHandlerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class NextRouteHandlerAuthStorageAdapter extends CookieAuthStorageAdapter {
}
}

export function createRouteHandlerSupabaseClient<
export function createRouteHandlerClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/serverActionClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { createRouteHandlerSupabaseClient } from './routeHandlerClient';
import { createRouteHandlerClient } from './routeHandlerClient';

export const createServerActionSupabaseClient = createRouteHandlerSupabaseClient;
export const createServerActionClient = createRouteHandlerClient;
4 changes: 1 addition & 3 deletions packages/nextjs/src/serverComponentClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class NextServerComponentAuthStorageAdapter extends CookieAuthStorageAdapter {
}
}

export const createRouteHandlerSupabaseClient = createServerComponentSupabaseClient;
silentworks marked this conversation as resolved.
Show resolved Hide resolved

export function createServerComponentSupabaseClient<
export function createServerComponentClient<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
Expand Down