The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
add pkce steps and migration guides for nextjs, nextjs-pages and remix
Jon Meyers14aec406438f
diff --git a/apps/docs/pages/guides/auth/auth-helpers/nextjs-pages.mdx b/apps/docs/pages/guides/auth/auth-helpers/nextjs-pages.mdxindex dd47ce758bd..1063118b065 100644--- a/apps/docs/pages/guides/auth/auth-helpers/nextjs-pages.mdx+++ b/apps/docs/pages/guides/auth/auth-helpers/nextjs-pages.mdx@@ -134,6 +134,65 @@ function MyApp({You can now determine if a user is authenticated by checking that the `user` object returned by the `useUser()` hook is defined.+### Code Exchange API Route++The `Code Exchange` API route is required for the [server-side auth flow](https://supabase.com/docs/guides/auth/server-side-rendering) implemented by the Next.js Auth Helpers. It exchanges an auth `code` for the user's `session`, which is set as a cookie for future requests made to Supabase.++<Tabs+ scrollable+ size="small"+ type="underlined"+ defaultActiveId="js"+>+<TabPanel id="js" label="JavaScript">++Create a new file at `pages/api/auth/callback.js` and populate with the following:++```jsx title="pages/api/auth/callback.js"+import { NextApiHandler } from 'next'+import { createPagesServerClient } from '@supabase/auth-helpers-nextjs'++const handler = async (req, res) => {+ const { code } = req.query++ if (code) {+ const supabase = createPagesServerClient({ req, res })+ await supabase.auth.exchangeCodeForSession(String(code))+ }++ res.redirect('/')+}++export default handler+```++</TabPanel>++<TabPanel id="ts" label="TypeScript">++Create a new file at `pages/api/auth/callback.ts` and populate with the following:++```tsx title="pages/api/auth/callback.ts"+import { NextApiHandler } from 'next'+import { createPagesServerClient } from '@supabase/auth-helpers-nextjs'++const handler: NextApiHandler = async (req, res) => {+ const { code } = req.query++ if (code) {+ const supabase = createPagesServerClient({ req, res })+ await supabase.auth.exchangeCodeForSession(String(code))+ }++ res.redirect('/')+}++export default handler+```++</TabPanel>+</Tabs>+## Usage with TypeScriptYou can pass types that were [generated with the Supabase CLI](/docs/reference/javascript/typescript-support#generating-types) to the Supabase Client to get enhanced type safety and auto completion:@@ -590,6 +649,35 @@ export const config = {## Migration Guide+### Migrating to v0.7.X++#### PKCE Auth Flow++PKCE is the new server-side auth flow implemented by the Next.js Auth Helpers. It requires a new API route for `/api/auth/callback` that exchanges an auth `code` for the user's `session`.++Check the [Code Exchange API Route steps](/docs/guides/auth/auth-helpers/nextjs-pages#code-exchange-api-route) above to implement this route.++#### Authentication++For authentication methods that have a `redirectTo` or `emailRedirectTo`, this must be set to this new code exchange API Route - `/api/auth/callback`. This is an example with the `signUp` function:++```jsx+supabase.auth.signUp({+ email: '[email protected]',+ password: 'sup3rs3cur3',+ options: {+ emailRedirectTo: 'http://localhost:3000/auth/callback',+ },+})+```++#### Deprecated Functions++With v0.7.x of the Next.js Auth Helpers a new naming convention has been implemented for createClient functions. The `createBrowserSupabaseClient` and `createServerSupabaseClient` functions have been marked as deprecated, and will be removed in a future version of the Auth Helpers.++- `createBrowserSupabaseClient` has been replaced with `createPagesBrowserClient`+- `createServerSupabaseClient` has been replaced with `createPagesServerClient`+### Migrating to v0.5.XTo make these helpers more flexible as well as more maintainable and easier to upgrade for new versions of Next.js, we're stripping them down to the most useful part which is managing the cookies and giving you an authenticated supabase-js client in any environment (client, server, middleware/edge).diff --git a/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdx b/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdxindex 8131d278ab3..4b60b43a918 100644--- a/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdx+++ b/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdx@@ -701,6 +701,54 @@ See [refreshing session example](/docs/guides/auth/auth-helpers/nextjs#refresh-s- [Protected Routes](https://github.com/supabase/supabase/tree/master/examples/auth/nextjs/app/[id]/page.tsx)- [Conditional Rendering in Client Components with SSR](https://github.com/supabase/supabase/tree/master/examples/auth/nextjs/app/login-form.tsx)+## Migration Guide++### Migrating to v0.7.X++#### PKCE Auth Flow++PKCE is the new server-side auth flow implemented by the Next.js Auth Helpers. It requires a new Route Handler for `/auth/callback` that exchanges an auth `code` for the user's `session`.++Check the [Code Exchange Route steps](/docs/guides/auth/auth-helpers/nextjs#code-exchange-route) above to implement this Route Handler.++#### Authentication++For authentication methods that have a `redirectTo` or `emailRedirectTo`, this must be set to this new code exchange route handler - `/auth/callback`. This is an example with the `signUp` function:++```jsx+supabase.auth.signUp({+ email: '[email protected]',+ password: 'sup3rs3cur3',+ options: {+ emailRedirectTo: 'http://localhost:3000/auth/callback',+ },+})+```++#### Deprecated Functions++With v0.7.x of the Next.js Auth Helpers a new naming convention has been implemented for createClient functions. The `createMiddlewareSupabaseClient`, `createBrowserSupabaseClient`, `createServerComponentSupabaseClient` and `createRouteHandlerSupabaseClient` functions have been marked as deprecated, and will be removed in a future version of the Auth Helpers.++- `createMiddlewareSupabaseClient` has been replaced with `createMiddlewareClient`+- `createBrowserSupabaseClient` has been replaced with `createClientComponentClient`+- `createServerComponentSupabaseClient` has been replaced with `createServerComponentClient`+- `createRouteHandlerSupabaseClient` has been replaced with `createRouteHandlerClient`++#### createClientComponentClient returns singleton++You no longer need to implement logic to ensure there is only a single instance of the Supabase Client shared across all Client Components - this is now handled by the `createClientComponentClient` function. Call it as many times as you want!++```jsx+"use client";++import { createClientComponentClient } from "@supabase/auth-helpers-nextjs";++export default function() {+ const supabase = createClientComponentClient();+ return ...+}+```+export const Page = ({ children }) => <Layout meta={meta} children={children} />export default Pagediff --git a/apps/docs/pages/guides/auth/auth-helpers/remix.mdx b/apps/docs/pages/guides/auth/auth-helpers/remix.mdxindex 6fb00ba51c6..98ff6f57c94 100644--- a/apps/docs/pages/guides/auth/auth-helpers/remix.mdx+++ b/apps/docs/pages/guides/auth/auth-helpers/remix.mdx@@ -61,6 +61,82 @@ SUPABASE_URL=YOUR_SUPABASE_URLSUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY```+### Code Exchange Route++The `Code Exchange` route is required for the [server-side auth flow](https://supabase.com/docs/guides/auth/server-side-rendering) implemented by the Remix Auth Helpers. It exchanges an auth `code` for the user's `session`, which is set as a cookie for future requests made to Supabase.++<Tabs+ scrollable+ size="small"+ type="underlined"+ defaultActiveId="js"+>+<TabPanel id="js" label="JavaScript">++Create a new file at `app/routes/auth.callback.jsx` and populate with the following:++```jsx title="app/routes/auth.callback.jsx"+import { redirect } from '@remix-run/node'+import { createServerClient } from '@supabase/auth-helpers-remix'++export const loader = async ({ request }) => {+ const response = new Response()+ const url = new URL(request.url)+ const code = url.searchParams.get('code')++ if (code) {+ const supabaseClient = createServerClient(+ process.env.SUPABASE_URL,+ process.env.SUPABASE_ANON_KEY,+ { request, response }+ )+ await supabaseClient.auth.exchangeCodeForSession(code)+ }++ return redirect('/', {+ headers: response.headers,+ })+}+```++</TabPanel>++<TabPanel id="ts" label="TypeScript">++Create a new file at `app/routes/auth.callback.tsx` and populate with the following:++```tsx title="app/routes/auth.callback.tsx"+import { redirect } from '@remix-run/node'+import { createServerClient } from '@supabase/auth-helpers-remix'++import type { Database } from 'db_types'+import type { LoaderArgs } from '@remix-run/node'++export const loader = async ({ request }: LoaderArgs) => {+ const response = new Response()+ const url = new URL(request.url)+ const code = url.searchParams.get('code')++ if (code) {+ const supabaseClient = createServerClient<Database>(+ process.env.SUPABASE_URL!,+ process.env.SUPABASE_ANON_KEY!,+ { request, response }+ )+ await supabaseClient.auth.exchangeCodeForSession(code)+ }++ return redirect('/', {+ headers: response.headers,+ })+}+```++> `Database` is a TypeScript definitions file [generated by the Supabase CLI](/docs/reference/javascript/typescript-support#generating-types).++</TabPanel>+</Tabs>+## Server-sideThe Supabase client can now be used server-side - in loaders and actions - by calling the `createServerClient` function.@@ -507,6 +583,9 @@ export default function Login() {const handleGitHubLogin = async () => {await supabase.auth.signInWithOAuth({provider: 'github',+ options: {+ redirectTo: 'http://localhost:3000/auth/callback',+ },})}@@ -542,6 +621,9 @@ export default function Login() {const handleGitHubLogin = async () => {await supabase.auth.signInWithOAuth({provider: 'github',+ options: {+ redirectTo: 'http://localhost:3000/auth/callback',+ },})}@@ -685,6 +767,30 @@ export default function Index() {> Ensure you have [enabled replication](https://app.supabase.com/project/_/database/replication) on the table you are subscribing to.+## Migration Guide++### Migrating to v0.2.0++#### PKCE Auth Flow++PKCE is the new server-side auth flow implemented by the Remix Auth Helpers. It requires a new `loader` route for `/auth/callback` that exchanges an auth `code` for the user's `session`.++Check the [Code Exchange Route steps](/docs/guides/auth/auth-helpers/remix#code-exchange-route) above to implement this route.++#### Authentication++For authentication methods that have a `redirectTo` or `emailRedirectTo`, this must be set to this new code exchange API Route - `/api/auth/callback`. This is an example with the `signUp` function:++```jsx+supabaseClient.auth.signUp({+ email: '[email protected]',+ password: 'sup3rs3cur3',+ options: {+ emailRedirectTo: 'http://localhost:3000/auth/callback',+ },+})+```+export const Page = ({ children }) => <Layout meta={meta} children={children} />export default Page