From 3098c2144a3b0367a3e85ca7496f434b4195702d Mon Sep 17 00:00:00 2001 From: Jon Meyers Date: Wed, 17 May 2023 12:30:45 +1000 Subject: [PATCH 1/2] implement consistent naming convention for createClient functions --- .../{browserClient.ts => clientComponentClient.ts} | 2 +- packages/nextjs/src/index.ts | 13 +++++++------ packages/nextjs/src/middlewareClient.ts | 2 +- packages/nextjs/src/pagesBrowserClient.ts | 3 +++ .../src/{serverClient.ts => pagesServerClient.ts} | 2 +- packages/nextjs/src/routeHandlerClient.ts | 2 +- packages/nextjs/src/serverActionClient.ts | 4 ++-- packages/nextjs/src/serverComponentClient.ts | 4 +--- 8 files changed, 17 insertions(+), 15 deletions(-) rename packages/nextjs/src/{browserClient.ts => clientComponentClient.ts} (96%) create mode 100644 packages/nextjs/src/pagesBrowserClient.ts rename packages/nextjs/src/{serverClient.ts => pagesServerClient.ts} (98%) diff --git a/packages/nextjs/src/browserClient.ts b/packages/nextjs/src/clientComponentClient.ts similarity index 96% rename from packages/nextjs/src/browserClient.ts rename to packages/nextjs/src/clientComponentClient.ts index e9f0e9da..81658cca 100644 --- a/packages/nextjs/src/browserClient.ts +++ b/packages/nextjs/src/clientComponentClient.ts @@ -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' diff --git a/packages/nextjs/src/index.ts b/packages/nextjs/src/index.ts index 2429bdac..eac30b8b 100644 --- a/packages/nextjs/src/index.ts +++ b/packages/nextjs/src/index.ts @@ -9,9 +9,10 @@ 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'; diff --git a/packages/nextjs/src/middlewareClient.ts b/packages/nextjs/src/middlewareClient.ts index 3994fd54..4fc7a91d 100644 --- a/packages/nextjs/src/middlewareClient.ts +++ b/packages/nextjs/src/middlewareClient.ts @@ -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' diff --git a/packages/nextjs/src/pagesBrowserClient.ts b/packages/nextjs/src/pagesBrowserClient.ts new file mode 100644 index 00000000..4de1c952 --- /dev/null +++ b/packages/nextjs/src/pagesBrowserClient.ts @@ -0,0 +1,3 @@ +import { createClientComponentClient } from './clientComponentClient'; + +export const createPagesBrowserClient = createClientComponentClient; diff --git a/packages/nextjs/src/serverClient.ts b/packages/nextjs/src/pagesServerClient.ts similarity index 98% rename from packages/nextjs/src/serverClient.ts rename to packages/nextjs/src/pagesServerClient.ts index 11581d64..707dadd0 100644 --- a/packages/nextjs/src/serverClient.ts +++ b/packages/nextjs/src/pagesServerClient.ts @@ -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' diff --git a/packages/nextjs/src/routeHandlerClient.ts b/packages/nextjs/src/routeHandlerClient.ts index d0e88930..9a37ed9a 100644 --- a/packages/nextjs/src/routeHandlerClient.ts +++ b/packages/nextjs/src/routeHandlerClient.ts @@ -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' diff --git a/packages/nextjs/src/serverActionClient.ts b/packages/nextjs/src/serverActionClient.ts index 050d21ed..a4535daf 100644 --- a/packages/nextjs/src/serverActionClient.ts +++ b/packages/nextjs/src/serverActionClient.ts @@ -1,3 +1,3 @@ -import { createRouteHandlerSupabaseClient } from './routeHandlerClient'; +import { createRouteHandlerClient } from './routeHandlerClient'; -export const createServerActionSupabaseClient = createRouteHandlerSupabaseClient; +export const createServerActionClient = createRouteHandlerClient; diff --git a/packages/nextjs/src/serverComponentClient.ts b/packages/nextjs/src/serverComponentClient.ts index 575dbe6b..12d322de 100644 --- a/packages/nextjs/src/serverComponentClient.ts +++ b/packages/nextjs/src/serverComponentClient.ts @@ -34,9 +34,7 @@ class NextServerComponentAuthStorageAdapter extends CookieAuthStorageAdapter { } } -export const createRouteHandlerSupabaseClient = createServerComponentSupabaseClient; - -export function createServerComponentSupabaseClient< +export function createServerComponentClient< Database = any, SchemaName extends string & keyof Database = 'public' extends keyof Database ? 'public' From e77ca92e9ca56b120f429dc3c7fc506cd4b0b491 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Thu, 18 May 2023 01:26:16 +0000 Subject: [PATCH 2/2] Add deprecated functions and changeset --- .changeset/six-eggs-search.md | 5 ++ packages/nextjs/src/deprecated.ts | 106 ++++++++++++++++++++++++++++++ packages/nextjs/src/index.ts | 7 ++ 3 files changed, 118 insertions(+) create mode 100644 .changeset/six-eggs-search.md create mode 100644 packages/nextjs/src/deprecated.ts diff --git a/.changeset/six-eggs-search.md b/.changeset/six-eggs-search.md new file mode 100644 index 00000000..b97bc838 --- /dev/null +++ b/.changeset/six-eggs-search.md @@ -0,0 +1,5 @@ +--- +'@supabase/auth-helpers-nextjs': patch +--- + +[BREAKING CHANGES]: Renamed createBrowserSupabaseClient to createPagesBrowserClient, createServerSupabaseClient to createPagesServerClient and createMiddlewareSupabaseClient to createMiddlewareClient diff --git a/packages/nextjs/src/deprecated.ts b/packages/nextjs/src/deprecated.ts new file mode 100644 index 00000000..1052b1c6 --- /dev/null +++ b/packages/nextjs/src/deprecated.ts @@ -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; + cookieOptions?: CookieOptionsWithName; +} = {}) { + console.warn( + 'Please utilize the `createPagesBrowserClient` function instead of the deprecated `createBrowserSupabaseClient` function.' + ); + return createPagesBrowserClient({ + 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; + cookieOptions?: CookieOptionsWithName; + } = {} +) { + console.warn( + 'Please utilize the `createPagesServerClient` function instead of the deprecated `createServerSupabaseClient` function.' + ); + return createPagesServerClient(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; + cookieOptions?: CookieOptionsWithName; + } = {} +) { + console.warn( + 'Please utilize the `createMiddlewareClient function instead of the deprecated `createMiddlewareSupabaseClient` function.' + ); + + return createMiddlewareClient(context, { + supabaseUrl, + supabaseKey, + options, + cookieOptions + }); +} diff --git a/packages/nextjs/src/index.ts b/packages/nextjs/src/index.ts index eac30b8b..1de0a6f6 100644 --- a/packages/nextjs/src/index.ts +++ b/packages/nextjs/src/index.ts @@ -16,3 +16,10 @@ export { createClientComponentClient } from './clientComponentClient'; export { createServerComponentClient } from './serverComponentClient'; export { createRouteHandlerClient } from './routeHandlerClient'; export { createServerActionClient } from './serverActionClient'; + +// Deprecated Functions +export { + createBrowserSupabaseClient, + createServerSupabaseClient, + createMiddlewareSupabaseClient +} from './deprecated';