The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
OAuth Consent Block (#48917)
Saxon Fletchera045804e735c
diff --git a/apps/ui-library/app/example/oauth-consent/layout.tsx b/apps/ui-library/app/example/oauth-consent/layout.tsxnew file mode 100644index 00000000000..bb6c1d2d25c--- /dev/null+++ b/apps/ui-library/app/example/oauth-consent/layout.tsx@@ -0,0 +1,19 @@+import { Metadata } from 'next'++import { BaseInjector } from './../base-injector'++export const metadata: Metadata = {+ title: 'OAuth Consent Example',+}++export default function RootLayout({ children }: { children: React.ReactNode }) {+ return (+ <>+ <BaseInjector />+ <div className="relative flex h-screen w-full items-center justify-center bg-studio p-6 preview md:p-10">+ <div className="pointer-events-none absolute z-0 h-full w-full bg-[radial-gradient(oklch(from_var(--foreground-default)_l_c_h_/_0.02)_1px,transparent_1px)] bg-size-[16px_16px] mask-[radial-gradient(ellipse_50%_50%_at_50%_50%,#000_70%,transparent_100%)]" />+ <div className="z-10 w-full max-w-lg">{children}</div>+ </div>+ </>+ )+}diff --git a/apps/ui-library/app/example/oauth-consent/page.tsx b/apps/ui-library/app/example/oauth-consent/page.tsxnew file mode 100644index 00000000000..cd62b576450--- /dev/null+++ b/apps/ui-library/app/example/oauth-consent/page.tsx@@ -0,0 +1,12 @@+import { OAuthConsentCard } from '@/registry/default/blocks/oauth-consent/components/oauth-consent'++export default function OAuthConsentDemo() {+ return (+ <OAuthConsentCard+ clientName="Claude Desktop"+ redirectUri="http://localhost:3000/callback"+ email="[email protected]"+ scopes={['openid', 'profile']}+ />+ )+}diff --git a/apps/ui-library/components/framework-selector.tsx b/apps/ui-library/components/framework-selector.tsxindex 13bfa5655ba..c3eeeb4c704 100644--- a/apps/ui-library/components/framework-selector.tsx+++ b/apps/ui-library/components/framework-selector.tsx@@ -3,7 +3,7 @@import { usePathname, useRouter } from 'next/navigation'import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from 'ui'-import { componentPages, frameworkTitles } from '@/config/docs'+import { componentPages, frameworkTitles, oauthBlocks } from '@/config/docs'import { useFramework } from '@/context/framework-context'const frameworks = Object.keys(frameworkTitles)@@ -26,7 +26,7 @@ export function FrameworkSelector() {}// Get the supported frameworks for this component- const componentItem = componentPages.items.find(+ const componentItem = [...componentPages.items, ...oauthBlocks.items].find((item) => item.href?.split('/').pop() === docTitle.toLowerCase())// Use the supportedFrameworks property if it exists, otherwise default to all frameworksdiff --git a/apps/ui-library/components/side-navigation.tsx b/apps/ui-library/components/side-navigation.tsxindex 359467930c2..b0932110c33 100644--- a/apps/ui-library/components/side-navigation.tsx+++ b/apps/ui-library/components/side-navigation.tsx@@ -3,7 +3,7 @@ import Link from 'next/link'import { CommandMenu } from './command-menu'import { ThemeSwitcherDropdown } from './theme-switcher-dropdown'import NavigationItem from '@/components/side-navigation-item'-import { componentPages, gettingStarted, platformBlocks } from '@/config/docs'+import { componentPages, gettingStarted, oauthBlocks, platformBlocks } from '@/config/docs'function SideNavigation() {return (@@ -88,6 +88,14 @@ function SideNavigation() {))}</div></div>+ <div className="pb-6">+ <div className="font-mono uppercase text-xs text-foreground-lighter/75 mb-2 px-6 tracking-widest">+ {oauthBlocks.title}+ </div>+ {oauthBlocks.items.map((item, i) => (+ <NavigationItem item={item} key={`${item.href}-${i}`} />+ ))}+ </div><div className="pb-6"><div className="font-mono uppercase text-xs text-foreground-lighter/75 mb-2 px-6 tracking-widest">{platformBlocks.title}diff --git a/apps/ui-library/config/docs.ts b/apps/ui-library/config/docs.tsindex e0585e27e78..3e496318a66 100644--- a/apps/ui-library/config/docs.ts+++ b/apps/ui-library/config/docs.ts@@ -36,6 +36,20 @@ export const platformBlocks: SidebarNavGroup = {],}+export const oauthBlocks: SidebarNavGroup = {+ title: 'OAuth',+ items: [+ {+ title: 'OAuth Consent',+ supportedFrameworks: ['nextjs', 'react-router', 'tanstack', 'react'],+ href: '/docs/nextjs/oauth-consent',+ items: [],+ new: true,+ commandItemLabel: 'OAuth Consent',+ },+ ],+}+// Component definitions with supported frameworksexport const componentPages: SidebarNavGroup = {title: 'Components',@@ -133,6 +147,10 @@ export const COMMAND_ITEMS = [label: item.commandItemLabel,href: item.href,})),+ ...oauthBlocks.items.map((item) => ({+ label: item.commandItemLabel,+ href: item.href,+ })),]// Framework titles for displaydiff --git a/apps/ui-library/content/docs/nextjs/oauth-consent.mdx b/apps/ui-library/content/docs/nextjs/oauth-consent.mdxnew file mode 100644index 00000000000..ae473e57a1f--- /dev/null+++ b/apps/ui-library/content/docs/nextjs/oauth-consent.mdx@@ -0,0 +1,77 @@+---+title: OAuth Consent+description: OAuth 2.1 consent block for Next.js+---++<BlockPreview name="oauth-consent" />++## Installation++<BlockItem+ name="oauth-consent-nextjs"+ description="OAuth 2.1 consent screen and the /oauth/consent route"+/>++## Folder structure++This block includes the [Supabase client](/library/docs/nextjs/client). If you already have one installed, you can skip overwriting it.++<RegistryBlock itemName="oauth-consent-nextjs" />++## Usage++This block installs an OAuth 2.1 consent route at `/oauth/consent`. It is designed for an app that already has authentication: it does not install sign-in, sign-up, or callback routes.++When the visitor has no session, the consent screen redirects to `/auth/login` and preserves the original consent URL in the `next` query parameter. Update the `signInPath` prop in `app/oauth/consent/page.tsx` if your sign-in route is different.++After sign-in, your login page must send the visitor back to the path in `next`; otherwise the OAuth flow stops at your login screen. The password-based auth and social auth blocks follow `next` automatically. For a custom login page, validate that `next` is a relative path before redirecting to it:++```ts+// After sign-in succeeds:+const next = new URLSearchParams(window.location.search).get('next')+try {+ const nextUrl = new URL(next ?? '/protected', window.location.origin)+ router.push(+ nextUrl.origin === window.location.origin+ ? `${nextUrl.pathname}${nextUrl.search}${nextUrl.hash}`+ : '/protected'+ )+} catch {+ router.push('/protected')+}+```++Set the `productName` prop to replace the `Your product` placeholder in the consent header.++Your middleware must let unauthenticated requests reach `/oauth/consent`. The middleware in `lib/supabase/middleware.ts` exempts only `/oauth/consent`. Middleware that redirects to a login page before the consent route runs drops the authorization and ends the OAuth flow at your login screen.++### Getting started++After installing the block, you'll have the following environment variables in your `.env.local` file:++```env+NEXT_PUBLIC_SUPABASE_URL=+NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=+```++- If you're using supabase.com, you can find these values in the [Connect modal](https://supabase.com/dashboard/project/_?showConnect=true&connectTab=frameworks&framework=nextjs) under App Frameworks or in your project's [API settings](https://supabase.com/dashboard/project/_/settings/api).+- If you're using a local instance of Supabase, you can find these values by running `supabase start` or `supabase status` (if you already have it running).++### Configure the OAuth server++Enable the OAuth server in the Supabase Dashboard under **Authentication** > **OAuth Server**, then set its authorization URL path to `/oauth/consent`. For local development, set the following in `supabase/config.toml`:++```toml+[auth.oauth_server]+enabled = true+authorization_url_path = "/oauth/consent"+```++Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false`. Edit that section rather than adding a second one, which fails with `table oauth_server already exists`.++The route expects the `authorization_id` query parameter that Supabase Auth supplies during the authorization flow.++## Further reading++- [OAuth Server](https://supabase.com/docs/guides/auth/oauth-server)+- [Supabase Auth](https://supabase.com/docs/guides/auth)diff --git a/apps/ui-library/content/docs/react-router/oauth-consent.mdx b/apps/ui-library/content/docs/react-router/oauth-consent.mdxnew file mode 100644index 00000000000..755a79b25b1--- /dev/null+++ b/apps/ui-library/content/docs/react-router/oauth-consent.mdx@@ -0,0 +1,77 @@+---+title: OAuth Consent+description: OAuth 2.1 consent block for React Router+---++<BlockPreview name="oauth-consent" />++## Installation++<BlockItem+ name="oauth-consent-react-router"+ description="OAuth 2.1 consent screen and the /oauth/consent route"+/>++## Folder structure++This block includes the [Supabase client](/library/docs/react-router/client). If you already have one installed, you can skip overwriting it.++<RegistryBlock itemName="oauth-consent-react-router" />++## Usage++This block installs an OAuth 2.1 consent route at `/oauth/consent`. It is designed for an app that already has authentication: it does not install sign-in, sign-up, or callback routes.++When the visitor has no session, the consent screen redirects to `/auth/login` and preserves the original consent URL in the `next` query parameter. Update the `signInPath` prop in `app/routes/oauth.consent.tsx` if your sign-in route is different.++After sign-in, your login route must send the visitor back to the path in `next`; otherwise the OAuth flow stops at your login screen. The password-based auth and social auth blocks follow `next` automatically. For a custom login route, pass `next` through the form (for example with a hidden input), validate that it is a relative path, and redirect to it from the action:++```ts+// In the login action, after sign-in succeeds:+const origin = new URL(request.url).origin+const next = formData.get('next')+try {+ const nextUrl = new URL(typeof next === 'string' ? next : '/protected', origin)+ return redirect(+ nextUrl.origin === origin+ ? `${nextUrl.pathname}${nextUrl.search}${nextUrl.hash}`+ : '/protected',+ { headers }+ )+} catch {+ return redirect('/protected', { headers })+}+```++Set the `productName` prop to replace the `Your product` placeholder in the consent header.++### Getting started++After installing the block, you'll have the following environment variables in your `.env.local` file:++```env+VITE_SUPABASE_URL=+VITE_SUPABASE_PUBLISHABLE_KEY=+```++- If you're using supabase.com, you can find these values in the [Connect modal](https://supabase.com/dashboard/project/_?showConnect=true&connectTab=frameworks&framework=react&using=vite&with=supabasejs) under App Frameworks or in your project's [API settings](https://supabase.com/dashboard/project/_/settings/api).+- If you're using a local instance of Supabase, you can find these values by running `supabase start` or `supabase status` (if you already have it running).++### Configure the OAuth server++Enable the OAuth server in the Supabase Dashboard under **Authentication** > **OAuth Server**, then set its authorization URL path to `/oauth/consent`. For local development, set the following in `supabase/config.toml`:++```toml+[auth.oauth_server]+enabled = true+authorization_url_path = "/oauth/consent"+```++Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false`. Edit that section rather than adding a second one, which fails with `table oauth_server already exists`.++The route expects the `authorization_id` query parameter that Supabase Auth supplies during the authorization flow.++## Further reading++- [OAuth Server](https://supabase.com/docs/guides/auth/oauth-server)+- [Supabase Auth](https://supabase.com/docs/guides/auth)diff --git a/apps/ui-library/content/docs/react/oauth-consent.mdx b/apps/ui-library/content/docs/react/oauth-consent.mdxnew file mode 100644index 00000000000..b3caac21784--- /dev/null+++ b/apps/ui-library/content/docs/react/oauth-consent.mdx@@ -0,0 +1,93 @@+---+title: OAuth Consent+description: OAuth 2.1 consent block for React single-page applications+---++<BlockPreview name="oauth-consent" />++## Installation++<BlockItem+ name="oauth-consent-react"+ description="OAuth 2.1 consent component for an existing authenticated application"+/>++## Folder structure++This block includes the [Supabase client](/library/docs/react/client). If you already have one installed, you can skip overwriting it.++<RegistryBlock itemName="oauth-consent-react" />++## Usage++This block provides an OAuth 2.1 consent component for an app that already has authentication. It does not install sign-in, sign-up, callback, or router-specific routes.++Render the component from your existing `/oauth/consent` route and pass the `authorization_id` query parameter. Set `signInPath` to the sign-in route in your app:++```tsx+import { OAuthConsent } from '@/components/oauth-consent'++export function ConsentPage() {+ const authorizationId = new URLSearchParams(window.location.search).get('authorization_id')++ return (+ <main className="flex min-h-svh items-center justify-center p-6 md:p-10">+ <OAuthConsent+ className="w-full max-w-lg"+ authorizationId={authorizationId}+ signInPath="/login"+ productName="Your product"+ />+ </main>+ )+}+```++When the visitor has no session, the consent screen redirects to `signInPath` and preserves the original consent URL in the `next` query parameter. After sign-in, your login page must send the visitor back to the path in `next`; otherwise the OAuth flow stops at your login screen. The password-based auth block follows `next` automatically. For a custom login page, validate that `next` is a relative path before redirecting to it:++```ts+// After sign-in succeeds:+const next = new URLSearchParams(window.location.search).get('next')+try {+ const nextUrl = new URL(next ?? '/protected', window.location.origin)+ location.href =+ nextUrl.origin === window.location.origin+ ? `${nextUrl.pathname}${nextUrl.search}${nextUrl.hash}`+ : '/protected'+} catch {+ location.href = '/protected'+}+```++Set the `productName` prop to replace the `Your product` placeholder in the consent header.++### Getting started++After installing the block, you'll have the following environment variables in your `.env.local` file:++```env+VITE_SUPABASE_URL=+VITE_SUPABASE_PUBLISHABLE_KEY=+```++- If you're using supabase.com, you can find these values in the [Connect modal](https://supabase.com/dashboard/project/_?showConnect=true&connectTab=frameworks&framework=react&using=vite&with=supabasejs) under App Frameworks or in your project's [API settings](https://supabase.com/dashboard/project/_/settings/api).+- If you're using a local instance of Supabase, you can find these values by running `supabase start` or `supabase status` (if you already have it running).++### Configure the OAuth server++Enable the OAuth server in the Supabase Dashboard under **Authentication** > **OAuth Server**, then set its authorization URL path to `/oauth/consent`. For local development, set the following in `supabase/config.toml`:++```toml+[auth.oauth_server]+enabled = true+authorization_url_path = "/oauth/consent"+```++Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false`. Edit that section rather than adding a second one, which fails with `table oauth_server already exists`.++The route expects the `authorization_id` query parameter that Supabase Auth supplies during the authorization flow.++## Further reading++- [OAuth Server](https://supabase.com/docs/guides/auth/oauth-server)+- [Supabase Auth](https://supabase.com/docs/guides/auth)diff --git a/apps/ui-library/content/docs/tanstack/oauth-consent.mdx b/apps/ui-library/content/docs/tanstack/oauth-consent.mdxnew file mode 100644index 00000000000..01e57232cac--- /dev/null+++ b/apps/ui-library/content/docs/tanstack/oauth-consent.mdx@@ -0,0 +1,69 @@+---+title: OAuth Consent+description: OAuth 2.1 consent block for TanStack Start+---++<BlockPreview name="oauth-consent" />++## Installation++<BlockItem+ name="oauth-consent-tanstack"+ description="OAuth 2.1 consent screen and the /oauth/consent route"+/>++## Folder structure++This block includes the [Supabase client](/library/docs/tanstack/client). If you already have one installed, you can skip overwriting it.++<RegistryBlock itemName="oauth-consent-tanstack" />++## Usage++This block installs an OAuth 2.1 consent route at `/oauth/consent`. It is designed for an app that already has authentication: it does not install sign-in, sign-up, or callback routes.++When the visitor has no session, the consent screen redirects to `/auth/login` and preserves the original consent URL in the `next` query parameter. Update the `signInPath` prop in `routes/oauth/consent.tsx` if your sign-in route is different.++After sign-in, your login page must send the visitor back to the path in `next`; otherwise the OAuth flow stops at your login screen. The password-based auth and social auth blocks follow `next` automatically. For a custom login page, validate that `next` is a relative path before redirecting to it:++```ts+// After sign-in succeeds:+const next = new URLSearchParams(window.location.search).get('next')+if (next?.startsWith('/') && !next.startsWith('//')) {+ // `next` may point outside the typed route tree, so use a full navigation.+ window.location.assign(next)+}+```++Set the `productName` prop to replace the `Your product` placeholder in the consent header.++### Getting started++After installing the block, you'll have the following environment variables in your `.env.local` file:++```env+VITE_SUPABASE_URL=+VITE_SUPABASE_PUBLISHABLE_KEY=+```++- If you're using supabase.com, you can find these values in the [Connect modal](https://supabase.com/dashboard/project/_?showConnect=true&connectTab=frameworks&framework=react&using=vite&with=supabasejs) under App Frameworks or in your project's [API settings](https://supabase.com/dashboard/project/_/settings/api).+- If you're using a local instance of Supabase, you can find these values by running `supabase start` or `supabase status` (if you already have it running).++### Configure the OAuth server++Enable the OAuth server in the Supabase Dashboard under **Authentication** > **OAuth Server**, then set its authorization URL path to `/oauth/consent`. For local development, set the following in `supabase/config.toml`:++```toml+[auth.oauth_server]+enabled = true+authorization_url_path = "/oauth/consent"+```++Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false`. Edit that section rather than adding a second one, which fails with `table oauth_server already exists`.++The route expects the `authorization_id` query parameter that Supabase Auth supplies during the authorization flow.++## Further reading++- [OAuth Server](https://supabase.com/docs/guides/auth/oauth-server)+- [Supabase Auth](https://supabase.com/docs/guides/auth)diff --git a/apps/ui-library/public/r/current-user-avatar-nextjs.json b/apps/ui-library/public/r/current-user-avatar-nextjs.jsonindex 44046fecd08..df4744d1512 100644--- a/apps/ui-library/public/r/current-user-avatar-nextjs.json+++ b/apps/ui-library/public/r/current-user-avatar-nextjs.json@@ -34,7 +34,7 @@},{"path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",- "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n","type": "registry:lib"},{diff --git a/apps/ui-library/public/r/dropzone-nextjs.json b/apps/ui-library/public/r/dropzone-nextjs.jsonindex a7db28470b1..a3bdfc16603 100644--- a/apps/ui-library/public/r/dropzone-nextjs.json+++ b/apps/ui-library/public/r/dropzone-nextjs.json@@ -31,7 +31,7 @@},{"path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",- "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n","type": "registry:lib"},{diff --git a/apps/ui-library/public/r/oauth-consent-nextjs.json b/apps/ui-library/public/r/oauth-consent-nextjs.jsonnew file mode 100644index 00000000000..a7c139492f0--- /dev/null+++ b/apps/ui-library/public/r/oauth-consent-nextjs.json@@ -0,0 +1,54 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "oauth-consent-nextjs",+ "type": "registry:block",+ "title": "OAuth Consent for Next.js",+ "description": "OAuth 2.1 consent screen and route for an existing authenticated application.",+ "dependencies": [+ "@supabase/ssr@latest",+ "@supabase/supabase-js@latest"+ ],+ "registryDependencies": [+ "button",+ "card",+ "https://supabase.com/library/r/safe-next-path.json"+ ],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "content": "'use client'\n\nimport { cn } from '@/lib/utils'\nimport {\n useOAuthConsent,\n type OAuthConsentDecision,\n} from '@/registry/default/blocks/oauth-consent/hooks/use-oauth-consent'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\n\nconst getInitial = (value: string) => value.trim().charAt(0).toUpperCase() || '?'\n\ninterface ConsentCardShellProps extends React.ComponentPropsWithoutRef<'div'> {\n clientName: string\n productName: string\n}\n\nfunction ConsentCardShell({\n clientName,\n productName,\n className,\n children,\n ...props\n}: ConsentCardShellProps) {\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader className=\"items-center space-y-4 text-center\">\n <div\n className=\"flex items-center justify-center\"\n aria-label={`${clientName} connecting to ${productName}`}\n >\n <div className=\"flex size-12 items-center justify-center rounded-full border bg-muted font-medium\">\n {getInitial(clientName)}\n </div>\n <div className=\"h-px w-8 bg-border\" aria-hidden=\"true\" />\n <div className=\"flex size-12 items-center justify-center rounded-full border bg-muted font-medium\">\n {getInitial(productName)}\n </div>\n </div>\n <div className=\"space-y-1.5\">\n <CardTitle className=\"text-2xl\">Authorize {clientName}</CardTitle>\n <CardDescription>Review what this client gets access to.</CardDescription>\n </div>\n </CardHeader>\n <CardContent className=\"space-y-6\">{children}</CardContent>\n </Card>\n </div>\n )\n}\n\nexport interface OAuthConsentCardProps extends React.ComponentPropsWithoutRef<'div'> {\n clientName: string\n productName?: string\n redirectUri: string\n email: string\n scopes?: string[]\n error?: string | null\n decision?: OAuthConsentDecision | null\n onApprove?: () => void\n onDeny?: () => void\n}\n\nexport function OAuthConsentCard({\n clientName,\n productName = 'Your product',\n redirectUri,\n email,\n scopes = [],\n error = null,\n decision = null,\n onApprove,\n onDeny,\n ...props\n}: OAuthConsentCardProps) {\n return (\n <ConsentCardShell clientName={clientName} productName={productName} {...props}>\n <dl className=\"divide-y rounded-lg border text-sm\">\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Client</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{clientName}</dd>\n </div>\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Redirects to</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{redirectUri}</dd>\n </div>\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Signed in as</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{email}</dd>\n </div>\n {scopes.length > 0 && (\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Scopes</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{scopes.join(', ')}</dd>\n </div>\n )}\n </dl>\n <p className=\"text-sm text-muted-foreground\">\n Allow access only if you recognize this application. It can act on your behalf only within\n the requested permissions and the access you already have.\n </p>\n {error && (\n <p role=\"alert\" className=\"text-sm text-destructive\">\n {error}\n </p>\n )}\n <div className=\"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\">\n <Button type=\"button\" variant=\"outline\" disabled={decision !== null} onClick={onDeny}>\n {decision === 'deny' ? 'Denying...' : 'Deny'}\n </Button>\n <Button type=\"button\" disabled={decision !== null} onClick={onApprove}>\n {decision === 'approve' ? 'Allowing...' : 'Allow access'}\n </Button>\n </div>\n </ConsentCardShell>\n )\n}\n\ninterface OAuthConsentProps extends React.ComponentPropsWithoutRef<'div'> {\n authorizationId?: string | null\n signInPath?: string\n productName?: string\n}\n\nexport function OAuthConsent({\n authorizationId,\n signInPath = '/auth/login',\n productName = 'Your product',\n ...props\n}: OAuthConsentProps) {\n const { details, email, error, isLoading, decision, approve, deny } = useOAuthConsent({\n authorizationId,\n signInPath,\n })\n\n if (isLoading || !details || !email) {\n return (\n <ConsentCardShell clientName=\"OAuth client\" productName={productName} {...props}>\n {isLoading ? (\n <p role=\"status\" className=\"text-sm text-muted-foreground\">\n Loading authorization request...\n </p>\n ) : (\n <p role=\"alert\" className=\"text-sm text-destructive\">\n {error ??\n 'Unable to load the authorization request. Start again from your OAuth client.'}\n </p>\n )}\n </ConsentCardShell>\n )\n }\n\n return (\n <OAuthConsentCard\n clientName={details.client.name}\n productName={productName}\n redirectUri={details.redirect_uri}\n email={email}\n scopes={details.scope.split(' ').filter(Boolean)}\n error={error}\n decision={decision}\n onApprove={() => void approve()}\n onDeny={() => void deny()}\n {...props}\n />\n )\n}\n",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "content": "import { isAuthSessionMissingError } from '@supabase/supabase-js'\nimport type { OAuthAuthorizationDetails } from '@supabase/supabase-js'\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\nimport { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'\nimport { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'\n\nexport type OAuthConsentDecision = 'approve' | 'deny'\n\nexport interface UseOAuthConsentOptions {\n authorizationId?: string | null\n signInPath?: string\n}\n\nconst withNextParam = (path: string, next: string) => {\n const url = new URL(path, window.location.origin)\n const searchParams = new URLSearchParams(url.search)\n searchParams.set('next', next)\n url.search = searchParams.toString()\n return `${url.pathname}${url.search}${url.hash}`\n}\n\nconst useOAuthConsent = ({\n authorizationId,\n signInPath = '/auth/login',\n}: UseOAuthConsentOptions) => {\n const [details, setDetails] = useState<OAuthAuthorizationDetails | null>(null)\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(true)\n const [decision, setDecision] = useState<OAuthConsentDecision | null>(null)\n const isDeciding = useRef(false)\n\n useEffect(() => {\n let active = true\n\n const loadAuthorization = async () => {\n setIsLoading(true)\n setError(null)\n setDetails(null)\n setDecision(null)\n\n if (!authorizationId) {\n setError('This page needs an authorization_id. Start again from your OAuth client.')\n setIsLoading(false)\n return\n }\n\n const supabase = createClient()\n const {\n data: { user },\n error: userError,\n } = await supabase.auth.getUser()\n\n if (userError && !isAuthSessionMissingError(userError)) {\n if (active) {\n setError(userError.message)\n setIsLoading(false)\n }\n return\n }\n\n if (!user) {\n const next = `${window.location.pathname}${window.location.search}`\n if (active) {\n window.location.replace(withNextParam(safeNextPath(signInPath, '/auth/login'), next))\n }\n return\n }\n\n const { data, error } = await supabase.auth.oauth.getAuthorizationDetails(authorizationId)\n if (error) {\n if (active) {\n setError(error.message)\n setIsLoading(false)\n }\n return\n }\n\n if (!('authorization_id' in data)) {\n if (active) {\n window.location.replace(data.redirect_url)\n }\n return\n }\n\n if (active) {\n setDetails(data)\n setIsLoading(false)\n }\n }\n\n void loadAuthorization()\n return () => {\n active = false\n }\n }, [authorizationId, signInPath])\n\n const decide = useCallback(\n async (action: OAuthConsentDecision) => {\n if (!authorizationId || isDeciding.current) return\n\n isDeciding.current = true\n setDecision(action)\n setError(null)\n const supabase = createClient()\n const result =\n action === 'approve'\n ? await supabase.auth.oauth.approveAuthorization(authorizationId, {\n skipBrowserRedirect: true,\n })\n : await supabase.auth.oauth.denyAuthorization(authorizationId, {\n skipBrowserRedirect: true,\n })\n\n if (result.error) {\n setError(result.error.message)\n setDecision(null)\n isDeciding.current = false\n return\n }\n\n if (!result.data?.redirect_url) {\n setError('The server did not return a redirect. Start again from your OAuth client.')\n setDecision(null)\n isDeciding.current = false\n return\n }\n\n window.location.assign(result.data.redirect_url)\n },\n [authorizationId]\n )\n\n return {\n details,\n email: details?.user.email ?? null,\n error,\n isLoading,\n decision,\n approve: () => decide('approve'),\n deny: () => decide('deny'),\n }\n}\n\ntype UseOAuthConsentReturn = ReturnType<typeof useOAuthConsent>\n\nexport { useOAuthConsent, type OAuthAuthorizationDetails, type UseOAuthConsentReturn }\n",+ "type": "registry:hook"+ },+ {+ "path": "registry/default/blocks/oauth-consent-nextjs/app/oauth/consent/page.tsx",+ "content": "import { OAuthConsent } from '@/registry/default/blocks/oauth-consent/components/oauth-consent'\n\nexport default async function ConsentPage({\n searchParams,\n}: {\n searchParams: Promise<{ authorization_id?: string }>\n}) {\n const { authorization_id } = await searchParams\n\n return (\n <main className=\"flex min-h-svh items-center justify-center p-6 md:p-10\">\n <OAuthConsent className=\"w-full max-w-lg\" authorizationId={authorization_id} />\n </main>\n )\n}\n",+ "type": "registry:page",+ "target": "app/oauth/consent/page.tsx"+ },+ {+ "path": "registry/default/clients/nextjs/lib/supabase/client.ts",+ "content": "import { createBrowserClient } from '@supabase/ssr'\n\nexport function createClient() {\n return createBrowserClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!\n )\n}\n",+ "type": "registry:lib"+ },+ {+ "path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "type": "registry:lib"+ },+ {+ "path": "registry/default/clients/nextjs/lib/supabase/server.ts",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { cookies } from 'next/headers'\n\n/**\n * If using Fluid compute: Don't put this client in a global variable. Always create a new client within each\n * function when using it.\n */\nexport async function createClient() {\n const cookieStore = await cookies()\n\n return createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return cookieStore.getAll()\n },\n setAll(cookiesToSet) {\n try {\n cookiesToSet.forEach(({ name, value, options }) =>\n cookieStore.set(name, value, options)\n )\n } catch {\n // The `setAll` method was called from a Server Component.\n // This can be ignored if you have middleware refreshing\n // user sessions.\n }\n },\n },\n }\n )\n}\n",+ "type": "registry:lib"+ }+ ],+ "envVars": {+ "NEXT_PUBLIC_SUPABASE_URL": "",+ "NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY": ""+ },+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` — edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```\n\nYou'll need to set the following environment variables in your project: `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY`."+}\ No newline at end of filediff --git a/apps/ui-library/public/r/oauth-consent-react-router.json b/apps/ui-library/public/r/oauth-consent-react-router.jsonnew file mode 100644index 00000000000..aa1bef8314b--- /dev/null+++ b/apps/ui-library/public/r/oauth-consent-react-router.json@@ -0,0 +1,49 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "oauth-consent-react-router",+ "type": "registry:block",+ "title": "OAuth Consent for React Router",+ "description": "OAuth 2.1 consent screen and route for an existing authenticated application.",+ "dependencies": [+ "@supabase/ssr@latest",+ "@supabase/supabase-js@latest"+ ],+ "registryDependencies": [+ "button",+ "card",+ "https://supabase.com/library/r/safe-next-path.json"+ ],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "content": "'use client'\n\nimport { cn } from '@/lib/utils'\nimport {\n useOAuthConsent,\n type OAuthConsentDecision,\n} from '@/registry/default/blocks/oauth-consent/hooks/use-oauth-consent'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\n\nconst getInitial = (value: string) => value.trim().charAt(0).toUpperCase() || '?'\n\ninterface ConsentCardShellProps extends React.ComponentPropsWithoutRef<'div'> {\n clientName: string\n productName: string\n}\n\nfunction ConsentCardShell({\n clientName,\n productName,\n className,\n children,\n ...props\n}: ConsentCardShellProps) {\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader className=\"items-center space-y-4 text-center\">\n <div\n className=\"flex items-center justify-center\"\n aria-label={`${clientName} connecting to ${productName}`}\n >\n <div className=\"flex size-12 items-center justify-center rounded-full border bg-muted font-medium\">\n {getInitial(clientName)}\n </div>\n <div className=\"h-px w-8 bg-border\" aria-hidden=\"true\" />\n <div className=\"flex size-12 items-center justify-center rounded-full border bg-muted font-medium\">\n {getInitial(productName)}\n </div>\n </div>\n <div className=\"space-y-1.5\">\n <CardTitle className=\"text-2xl\">Authorize {clientName}</CardTitle>\n <CardDescription>Review what this client gets access to.</CardDescription>\n </div>\n </CardHeader>\n <CardContent className=\"space-y-6\">{children}</CardContent>\n </Card>\n </div>\n )\n}\n\nexport interface OAuthConsentCardProps extends React.ComponentPropsWithoutRef<'div'> {\n clientName: string\n productName?: string\n redirectUri: string\n email: string\n scopes?: string[]\n error?: string | null\n decision?: OAuthConsentDecision | null\n onApprove?: () => void\n onDeny?: () => void\n}\n\nexport function OAuthConsentCard({\n clientName,\n productName = 'Your product',\n redirectUri,\n email,\n scopes = [],\n error = null,\n decision = null,\n onApprove,\n onDeny,\n ...props\n}: OAuthConsentCardProps) {\n return (\n <ConsentCardShell clientName={clientName} productName={productName} {...props}>\n <dl className=\"divide-y rounded-lg border text-sm\">\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Client</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{clientName}</dd>\n </div>\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Redirects to</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{redirectUri}</dd>\n </div>\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Signed in as</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{email}</dd>\n </div>\n {scopes.length > 0 && (\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Scopes</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{scopes.join(', ')}</dd>\n </div>\n )}\n </dl>\n <p className=\"text-sm text-muted-foreground\">\n Allow access only if you recognize this application. It can act on your behalf only within\n the requested permissions and the access you already have.\n </p>\n {error && (\n <p role=\"alert\" className=\"text-sm text-destructive\">\n {error}\n </p>\n )}\n <div className=\"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\">\n <Button type=\"button\" variant=\"outline\" disabled={decision !== null} onClick={onDeny}>\n {decision === 'deny' ? 'Denying...' : 'Deny'}\n </Button>\n <Button type=\"button\" disabled={decision !== null} onClick={onApprove}>\n {decision === 'approve' ? 'Allowing...' : 'Allow access'}\n </Button>\n </div>\n </ConsentCardShell>\n )\n}\n\ninterface OAuthConsentProps extends React.ComponentPropsWithoutRef<'div'> {\n authorizationId?: string | null\n signInPath?: string\n productName?: string\n}\n\nexport function OAuthConsent({\n authorizationId,\n signInPath = '/auth/login',\n productName = 'Your product',\n ...props\n}: OAuthConsentProps) {\n const { details, email, error, isLoading, decision, approve, deny } = useOAuthConsent({\n authorizationId,\n signInPath,\n })\n\n if (isLoading || !details || !email) {\n return (\n <ConsentCardShell clientName=\"OAuth client\" productName={productName} {...props}>\n {isLoading ? (\n <p role=\"status\" className=\"text-sm text-muted-foreground\">\n Loading authorization request...\n </p>\n ) : (\n <p role=\"alert\" className=\"text-sm text-destructive\">\n {error ??\n 'Unable to load the authorization request. Start again from your OAuth client.'}\n </p>\n )}\n </ConsentCardShell>\n )\n }\n\n return (\n <OAuthConsentCard\n clientName={details.client.name}\n productName={productName}\n redirectUri={details.redirect_uri}\n email={email}\n scopes={details.scope.split(' ').filter(Boolean)}\n error={error}\n decision={decision}\n onApprove={() => void approve()}\n onDeny={() => void deny()}\n {...props}\n />\n )\n}\n",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "content": "import { isAuthSessionMissingError } from '@supabase/supabase-js'\nimport type { OAuthAuthorizationDetails } from '@supabase/supabase-js'\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\nimport { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'\nimport { createClient } from '@/registry/default/clients/react-router/lib/supabase/client'\n\nexport type OAuthConsentDecision = 'approve' | 'deny'\n\nexport interface UseOAuthConsentOptions {\n authorizationId?: string | null\n signInPath?: string\n}\n\nconst withNextParam = (path: string, next: string) => {\n const url = new URL(path, window.location.origin)\n const searchParams = new URLSearchParams(url.search)\n searchParams.set('next', next)\n url.search = searchParams.toString()\n return `${url.pathname}${url.search}${url.hash}`\n}\n\nconst useOAuthConsent = ({\n authorizationId,\n signInPath = '/auth/login',\n}: UseOAuthConsentOptions) => {\n const [details, setDetails] = useState<OAuthAuthorizationDetails | null>(null)\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(true)\n const [decision, setDecision] = useState<OAuthConsentDecision | null>(null)\n const isDeciding = useRef(false)\n\n useEffect(() => {\n let active = true\n\n const loadAuthorization = async () => {\n setIsLoading(true)\n setError(null)\n setDetails(null)\n setDecision(null)\n\n if (!authorizationId) {\n setError('This page needs an authorization_id. Start again from your OAuth client.')\n setIsLoading(false)\n return\n }\n\n const supabase = createClient()\n const {\n data: { user },\n error: userError,\n } = await supabase.auth.getUser()\n\n if (userError && !isAuthSessionMissingError(userError)) {\n if (active) {\n setError(userError.message)\n setIsLoading(false)\n }\n return\n }\n\n if (!user) {\n const next = `${window.location.pathname}${window.location.search}`\n if (active) {\n window.location.replace(withNextParam(safeNextPath(signInPath, '/auth/login'), next))\n }\n return\n }\n\n const { data, error } = await supabase.auth.oauth.getAuthorizationDetails(authorizationId)\n if (error) {\n if (active) {\n setError(error.message)\n setIsLoading(false)\n }\n return\n }\n\n if (!('authorization_id' in data)) {\n if (active) {\n window.location.replace(data.redirect_url)\n }\n return\n }\n\n if (active) {\n setDetails(data)\n setIsLoading(false)\n }\n }\n\n void loadAuthorization()\n return () => {\n active = false\n }\n }, [authorizationId, signInPath])\n\n const decide = useCallback(\n async (action: OAuthConsentDecision) => {\n if (!authorizationId || isDeciding.current) return\n\n isDeciding.current = true\n setDecision(action)\n setError(null)\n const supabase = createClient()\n const result =\n action === 'approve'\n ? await supabase.auth.oauth.approveAuthorization(authorizationId, {\n skipBrowserRedirect: true,\n })\n : await supabase.auth.oauth.denyAuthorization(authorizationId, {\n skipBrowserRedirect: true,\n })\n\n if (result.error) {\n setError(result.error.message)\n setDecision(null)\n isDeciding.current = false\n return\n }\n\n if (!result.data?.redirect_url) {\n setError('The server did not return a redirect. Start again from your OAuth client.')\n setDecision(null)\n isDeciding.current = false\n return\n }\n\n window.location.assign(result.data.redirect_url)\n },\n [authorizationId]\n )\n\n return {\n details,\n email: details?.user.email ?? null,\n error,\n isLoading,\n decision,\n approve: () => decide('approve'),\n deny: () => decide('deny'),\n }\n}\n\ntype UseOAuthConsentReturn = ReturnType<typeof useOAuthConsent>\n\nexport { useOAuthConsent, type OAuthAuthorizationDetails, type UseOAuthConsentReturn }\n",+ "type": "registry:hook"+ },+ {+ "path": "registry/default/blocks/oauth-consent-react-router/app/routes/oauth.consent.tsx",+ "content": "import { useSearchParams } from 'react-router'\n\nimport { OAuthConsent } from '@/registry/default/blocks/oauth-consent/components/oauth-consent'\n\nexport default function ConsentRoute() {\n const [searchParams] = useSearchParams()\n\n return (\n <main className=\"flex min-h-svh items-center justify-center p-6 md:p-10\">\n <OAuthConsent\n className=\"w-full max-w-lg\"\n authorizationId={searchParams.get('authorization_id')}\n />\n </main>\n )\n}\n",+ "type": "registry:file",+ "target": "app/routes/oauth.consent.tsx"+ },+ {+ "path": "registry/default/clients/react-router/lib/supabase/client.ts",+ "content": "/// <reference types=\"vite/types/importMeta.d.ts\" />\nimport { createBrowserClient } from '@supabase/ssr'\n\nexport function createClient() {\n return createBrowserClient(\n import.meta.env.VITE_SUPABASE_URL!,\n import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY!\n )\n}\n",+ "type": "registry:lib"+ },+ {+ "path": "registry/default/clients/react-router/lib/supabase/server.ts",+ "content": "import { createServerClient, parseCookieHeader, serializeCookieHeader } from '@supabase/ssr'\n\nexport function createClient(request: Request) {\n const headers = new Headers()\n\n const supabase = createServerClient(\n process.env.VITE_SUPABASE_URL!,\n process.env.VITE_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return parseCookieHeader(request.headers.get('Cookie') ?? '') as {\n name: string\n value: string\n }[]\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value, options }) =>\n headers.append('Set-Cookie', serializeCookieHeader(name, value, options))\n )\n },\n },\n }\n )\n\n return { supabase, headers }\n}\n",+ "type": "registry:lib"+ }+ ],+ "envVars": {+ "VITE_SUPABASE_URL": "",+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""+ },+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` — edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```\n\nYou'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`."+}\ No newline at end of filediff --git a/apps/ui-library/public/r/oauth-consent-react.json b/apps/ui-library/public/r/oauth-consent-react.jsonnew file mode 100644index 00000000000..6326997caf7--- /dev/null+++ b/apps/ui-library/public/r/oauth-consent-react.json@@ -0,0 +1,37 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "oauth-consent-react",+ "type": "registry:block",+ "title": "OAuth Consent for React",+ "description": "OAuth 2.1 consent component for an existing authenticated application.",+ "dependencies": [+ "@supabase/supabase-js@latest"+ ],+ "registryDependencies": [+ "button",+ "card",+ "https://supabase.com/library/r/safe-next-path.json"+ ],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "content": "'use client'\n\nimport { cn } from '@/lib/utils'\nimport {\n useOAuthConsent,\n type OAuthConsentDecision,\n} from '@/registry/default/blocks/oauth-consent/hooks/use-oauth-consent'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\n\nconst getInitial = (value: string) => value.trim().charAt(0).toUpperCase() || '?'\n\ninterface ConsentCardShellProps extends React.ComponentPropsWithoutRef<'div'> {\n clientName: string\n productName: string\n}\n\nfunction ConsentCardShell({\n clientName,\n productName,\n className,\n children,\n ...props\n}: ConsentCardShellProps) {\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader className=\"items-center space-y-4 text-center\">\n <div\n className=\"flex items-center justify-center\"\n aria-label={`${clientName} connecting to ${productName}`}\n >\n <div className=\"flex size-12 items-center justify-center rounded-full border bg-muted font-medium\">\n {getInitial(clientName)}\n </div>\n <div className=\"h-px w-8 bg-border\" aria-hidden=\"true\" />\n <div className=\"flex size-12 items-center justify-center rounded-full border bg-muted font-medium\">\n {getInitial(productName)}\n </div>\n </div>\n <div className=\"space-y-1.5\">\n <CardTitle className=\"text-2xl\">Authorize {clientName}</CardTitle>\n <CardDescription>Review what this client gets access to.</CardDescription>\n </div>\n </CardHeader>\n <CardContent className=\"space-y-6\">{children}</CardContent>\n </Card>\n </div>\n )\n}\n\nexport interface OAuthConsentCardProps extends React.ComponentPropsWithoutRef<'div'> {\n clientName: string\n productName?: string\n redirectUri: string\n email: string\n scopes?: string[]\n error?: string | null\n decision?: OAuthConsentDecision | null\n onApprove?: () => void\n onDeny?: () => void\n}\n\nexport function OAuthConsentCard({\n clientName,\n productName = 'Your product',\n redirectUri,\n email,\n scopes = [],\n error = null,\n decision = null,\n onApprove,\n onDeny,\n ...props\n}: OAuthConsentCardProps) {\n return (\n <ConsentCardShell clientName={clientName} productName={productName} {...props}>\n <dl className=\"divide-y rounded-lg border text-sm\">\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Client</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{clientName}</dd>\n </div>\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Redirects to</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{redirectUri}</dd>\n </div>\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Signed in as</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{email}</dd>\n </div>\n {scopes.length > 0 && (\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Scopes</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{scopes.join(', ')}</dd>\n </div>\n )}\n </dl>\n <p className=\"text-sm text-muted-foreground\">\n Allow access only if you recognize this application. It can act on your behalf only within\n the requested permissions and the access you already have.\n </p>\n {error && (\n <p role=\"alert\" className=\"text-sm text-destructive\">\n {error}\n </p>\n )}\n <div className=\"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\">\n <Button type=\"button\" variant=\"outline\" disabled={decision !== null} onClick={onDeny}>\n {decision === 'deny' ? 'Denying...' : 'Deny'}\n </Button>\n <Button type=\"button\" disabled={decision !== null} onClick={onApprove}>\n {decision === 'approve' ? 'Allowing...' : 'Allow access'}\n </Button>\n </div>\n </ConsentCardShell>\n )\n}\n\ninterface OAuthConsentProps extends React.ComponentPropsWithoutRef<'div'> {\n authorizationId?: string | null\n signInPath?: string\n productName?: string\n}\n\nexport function OAuthConsent({\n authorizationId,\n signInPath = '/auth/login',\n productName = 'Your product',\n ...props\n}: OAuthConsentProps) {\n const { details, email, error, isLoading, decision, approve, deny } = useOAuthConsent({\n authorizationId,\n signInPath,\n })\n\n if (isLoading || !details || !email) {\n return (\n <ConsentCardShell clientName=\"OAuth client\" productName={productName} {...props}>\n {isLoading ? (\n <p role=\"status\" className=\"text-sm text-muted-foreground\">\n Loading authorization request...\n </p>\n ) : (\n <p role=\"alert\" className=\"text-sm text-destructive\">\n {error ??\n 'Unable to load the authorization request. Start again from your OAuth client.'}\n </p>\n )}\n </ConsentCardShell>\n )\n }\n\n return (\n <OAuthConsentCard\n clientName={details.client.name}\n productName={productName}\n redirectUri={details.redirect_uri}\n email={email}\n scopes={details.scope.split(' ').filter(Boolean)}\n error={error}\n decision={decision}\n onApprove={() => void approve()}\n onDeny={() => void deny()}\n {...props}\n />\n )\n}\n",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "content": "import { isAuthSessionMissingError } from '@supabase/supabase-js'\nimport type { OAuthAuthorizationDetails } from '@supabase/supabase-js'\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\nimport { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'\nimport { createClient } from '@/registry/default/clients/react/lib/supabase/client'\n\nexport type OAuthConsentDecision = 'approve' | 'deny'\n\nexport interface UseOAuthConsentOptions {\n authorizationId?: string | null\n signInPath?: string\n}\n\nconst withNextParam = (path: string, next: string) => {\n const url = new URL(path, window.location.origin)\n const searchParams = new URLSearchParams(url.search)\n searchParams.set('next', next)\n url.search = searchParams.toString()\n return `${url.pathname}${url.search}${url.hash}`\n}\n\nconst useOAuthConsent = ({\n authorizationId,\n signInPath = '/auth/login',\n}: UseOAuthConsentOptions) => {\n const [details, setDetails] = useState<OAuthAuthorizationDetails | null>(null)\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(true)\n const [decision, setDecision] = useState<OAuthConsentDecision | null>(null)\n const isDeciding = useRef(false)\n\n useEffect(() => {\n let active = true\n\n const loadAuthorization = async () => {\n setIsLoading(true)\n setError(null)\n setDetails(null)\n setDecision(null)\n\n if (!authorizationId) {\n setError('This page needs an authorization_id. Start again from your OAuth client.')\n setIsLoading(false)\n return\n }\n\n const supabase = createClient()\n const {\n data: { user },\n error: userError,\n } = await supabase.auth.getUser()\n\n if (userError && !isAuthSessionMissingError(userError)) {\n if (active) {\n setError(userError.message)\n setIsLoading(false)\n }\n return\n }\n\n if (!user) {\n const next = `${window.location.pathname}${window.location.search}`\n if (active) {\n window.location.replace(withNextParam(safeNextPath(signInPath, '/auth/login'), next))\n }\n return\n }\n\n const { data, error } = await supabase.auth.oauth.getAuthorizationDetails(authorizationId)\n if (error) {\n if (active) {\n setError(error.message)\n setIsLoading(false)\n }\n return\n }\n\n if (!('authorization_id' in data)) {\n if (active) {\n window.location.replace(data.redirect_url)\n }\n return\n }\n\n if (active) {\n setDetails(data)\n setIsLoading(false)\n }\n }\n\n void loadAuthorization()\n return () => {\n active = false\n }\n }, [authorizationId, signInPath])\n\n const decide = useCallback(\n async (action: OAuthConsentDecision) => {\n if (!authorizationId || isDeciding.current) return\n\n isDeciding.current = true\n setDecision(action)\n setError(null)\n const supabase = createClient()\n const result =\n action === 'approve'\n ? await supabase.auth.oauth.approveAuthorization(authorizationId, {\n skipBrowserRedirect: true,\n })\n : await supabase.auth.oauth.denyAuthorization(authorizationId, {\n skipBrowserRedirect: true,\n })\n\n if (result.error) {\n setError(result.error.message)\n setDecision(null)\n isDeciding.current = false\n return\n }\n\n if (!result.data?.redirect_url) {\n setError('The server did not return a redirect. Start again from your OAuth client.')\n setDecision(null)\n isDeciding.current = false\n return\n }\n\n window.location.assign(result.data.redirect_url)\n },\n [authorizationId]\n )\n\n return {\n details,\n email: details?.user.email ?? null,\n error,\n isLoading,\n decision,\n approve: () => decide('approve'),\n deny: () => decide('deny'),\n }\n}\n\ntype UseOAuthConsentReturn = ReturnType<typeof useOAuthConsent>\n\nexport { useOAuthConsent, type OAuthAuthorizationDetails, type UseOAuthConsentReturn }\n",+ "type": "registry:hook"+ },+ {+ "path": "registry/default/clients/react/lib/supabase/client.ts",+ "content": "import { createClient as createSupabaseClient } from '@supabase/supabase-js'\n\nexport function createClient() {\n return createSupabaseClient(\n import.meta.env.VITE_SUPABASE_URL!,\n import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY!\n )\n}\n",+ "type": "registry:lib"+ }+ ],+ "envVars": {+ "VITE_SUPABASE_URL": "",+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""+ },+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` — edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```\n\nYou'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`."+}\ No newline at end of filediff --git a/apps/ui-library/public/r/oauth-consent-tanstack.json b/apps/ui-library/public/r/oauth-consent-tanstack.jsonnew file mode 100644index 00000000000..34cc335915f--- /dev/null+++ b/apps/ui-library/public/r/oauth-consent-tanstack.json@@ -0,0 +1,49 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "oauth-consent-tanstack",+ "type": "registry:block",+ "title": "OAuth Consent for TanStack Start",+ "description": "OAuth 2.1 consent screen and route for an existing authenticated application.",+ "dependencies": [+ "@supabase/ssr@latest",+ "@supabase/supabase-js@latest"+ ],+ "registryDependencies": [+ "button",+ "card",+ "https://supabase.com/library/r/safe-next-path.json"+ ],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "content": "'use client'\n\nimport { cn } from '@/lib/utils'\nimport {\n useOAuthConsent,\n type OAuthConsentDecision,\n} from '@/registry/default/blocks/oauth-consent/hooks/use-oauth-consent'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\n\nconst getInitial = (value: string) => value.trim().charAt(0).toUpperCase() || '?'\n\ninterface ConsentCardShellProps extends React.ComponentPropsWithoutRef<'div'> {\n clientName: string\n productName: string\n}\n\nfunction ConsentCardShell({\n clientName,\n productName,\n className,\n children,\n ...props\n}: ConsentCardShellProps) {\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader className=\"items-center space-y-4 text-center\">\n <div\n className=\"flex items-center justify-center\"\n aria-label={`${clientName} connecting to ${productName}`}\n >\n <div className=\"flex size-12 items-center justify-center rounded-full border bg-muted font-medium\">\n {getInitial(clientName)}\n </div>\n <div className=\"h-px w-8 bg-border\" aria-hidden=\"true\" />\n <div className=\"flex size-12 items-center justify-center rounded-full border bg-muted font-medium\">\n {getInitial(productName)}\n </div>\n </div>\n <div className=\"space-y-1.5\">\n <CardTitle className=\"text-2xl\">Authorize {clientName}</CardTitle>\n <CardDescription>Review what this client gets access to.</CardDescription>\n </div>\n </CardHeader>\n <CardContent className=\"space-y-6\">{children}</CardContent>\n </Card>\n </div>\n )\n}\n\nexport interface OAuthConsentCardProps extends React.ComponentPropsWithoutRef<'div'> {\n clientName: string\n productName?: string\n redirectUri: string\n email: string\n scopes?: string[]\n error?: string | null\n decision?: OAuthConsentDecision | null\n onApprove?: () => void\n onDeny?: () => void\n}\n\nexport function OAuthConsentCard({\n clientName,\n productName = 'Your product',\n redirectUri,\n email,\n scopes = [],\n error = null,\n decision = null,\n onApprove,\n onDeny,\n ...props\n}: OAuthConsentCardProps) {\n return (\n <ConsentCardShell clientName={clientName} productName={productName} {...props}>\n <dl className=\"divide-y rounded-lg border text-sm\">\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Client</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{clientName}</dd>\n </div>\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Redirects to</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{redirectUri}</dd>\n </div>\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Signed in as</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{email}</dd>\n </div>\n {scopes.length > 0 && (\n <div className=\"flex items-center justify-between gap-6 p-4\">\n <dt className=\"text-muted-foreground\">Scopes</dt>\n <dd className=\"min-w-0 break-all text-right font-medium\">{scopes.join(', ')}</dd>\n </div>\n )}\n </dl>\n <p className=\"text-sm text-muted-foreground\">\n Allow access only if you recognize this application. It can act on your behalf only within\n the requested permissions and the access you already have.\n </p>\n {error && (\n <p role=\"alert\" className=\"text-sm text-destructive\">\n {error}\n </p>\n )}\n <div className=\"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\">\n <Button type=\"button\" variant=\"outline\" disabled={decision !== null} onClick={onDeny}>\n {decision === 'deny' ? 'Denying...' : 'Deny'}\n </Button>\n <Button type=\"button\" disabled={decision !== null} onClick={onApprove}>\n {decision === 'approve' ? 'Allowing...' : 'Allow access'}\n </Button>\n </div>\n </ConsentCardShell>\n )\n}\n\ninterface OAuthConsentProps extends React.ComponentPropsWithoutRef<'div'> {\n authorizationId?: string | null\n signInPath?: string\n productName?: string\n}\n\nexport function OAuthConsent({\n authorizationId,\n signInPath = '/auth/login',\n productName = 'Your product',\n ...props\n}: OAuthConsentProps) {\n const { details, email, error, isLoading, decision, approve, deny } = useOAuthConsent({\n authorizationId,\n signInPath,\n })\n\n if (isLoading || !details || !email) {\n return (\n <ConsentCardShell clientName=\"OAuth client\" productName={productName} {...props}>\n {isLoading ? (\n <p role=\"status\" className=\"text-sm text-muted-foreground\">\n Loading authorization request...\n </p>\n ) : (\n <p role=\"alert\" className=\"text-sm text-destructive\">\n {error ??\n 'Unable to load the authorization request. Start again from your OAuth client.'}\n </p>\n )}\n </ConsentCardShell>\n )\n }\n\n return (\n <OAuthConsentCard\n clientName={details.client.name}\n productName={productName}\n redirectUri={details.redirect_uri}\n email={email}\n scopes={details.scope.split(' ').filter(Boolean)}\n error={error}\n decision={decision}\n onApprove={() => void approve()}\n onDeny={() => void deny()}\n {...props}\n />\n )\n}\n",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "content": "import { isAuthSessionMissingError } from '@supabase/supabase-js'\nimport type { OAuthAuthorizationDetails } from '@supabase/supabase-js'\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\nimport { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'\nimport { createClient } from '@/registry/default/clients/tanstack/lib/supabase/client'\n\nexport type OAuthConsentDecision = 'approve' | 'deny'\n\nexport interface UseOAuthConsentOptions {\n authorizationId?: string | null\n signInPath?: string\n}\n\nconst withNextParam = (path: string, next: string) => {\n const url = new URL(path, window.location.origin)\n const searchParams = new URLSearchParams(url.search)\n searchParams.set('next', next)\n url.search = searchParams.toString()\n return `${url.pathname}${url.search}${url.hash}`\n}\n\nconst useOAuthConsent = ({\n authorizationId,\n signInPath = '/auth/login',\n}: UseOAuthConsentOptions) => {\n const [details, setDetails] = useState<OAuthAuthorizationDetails | null>(null)\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(true)\n const [decision, setDecision] = useState<OAuthConsentDecision | null>(null)\n const isDeciding = useRef(false)\n\n useEffect(() => {\n let active = true\n\n const loadAuthorization = async () => {\n setIsLoading(true)\n setError(null)\n setDetails(null)\n setDecision(null)\n\n if (!authorizationId) {\n setError('This page needs an authorization_id. Start again from your OAuth client.')\n setIsLoading(false)\n return\n }\n\n const supabase = createClient()\n const {\n data: { user },\n error: userError,\n } = await supabase.auth.getUser()\n\n if (userError && !isAuthSessionMissingError(userError)) {\n if (active) {\n setError(userError.message)\n setIsLoading(false)\n }\n return\n }\n\n if (!user) {\n const next = `${window.location.pathname}${window.location.search}`\n if (active) {\n window.location.replace(withNextParam(safeNextPath(signInPath, '/auth/login'), next))\n }\n return\n }\n\n const { data, error } = await supabase.auth.oauth.getAuthorizationDetails(authorizationId)\n if (error) {\n if (active) {\n setError(error.message)\n setIsLoading(false)\n }\n return\n }\n\n if (!('authorization_id' in data)) {\n if (active) {\n window.location.replace(data.redirect_url)\n }\n return\n }\n\n if (active) {\n setDetails(data)\n setIsLoading(false)\n }\n }\n\n void loadAuthorization()\n return () => {\n active = false\n }\n }, [authorizationId, signInPath])\n\n const decide = useCallback(\n async (action: OAuthConsentDecision) => {\n if (!authorizationId || isDeciding.current) return\n\n isDeciding.current = true\n setDecision(action)\n setError(null)\n const supabase = createClient()\n const result =\n action === 'approve'\n ? await supabase.auth.oauth.approveAuthorization(authorizationId, {\n skipBrowserRedirect: true,\n })\n : await supabase.auth.oauth.denyAuthorization(authorizationId, {\n skipBrowserRedirect: true,\n })\n\n if (result.error) {\n setError(result.error.message)\n setDecision(null)\n isDeciding.current = false\n return\n }\n\n if (!result.data?.redirect_url) {\n setError('The server did not return a redirect. Start again from your OAuth client.')\n setDecision(null)\n isDeciding.current = false\n return\n }\n\n window.location.assign(result.data.redirect_url)\n },\n [authorizationId]\n )\n\n return {\n details,\n email: details?.user.email ?? null,\n error,\n isLoading,\n decision,\n approve: () => decide('approve'),\n deny: () => decide('deny'),\n }\n}\n\ntype UseOAuthConsentReturn = ReturnType<typeof useOAuthConsent>\n\nexport { useOAuthConsent, type OAuthAuthorizationDetails, type UseOAuthConsentReturn }\n",+ "type": "registry:hook"+ },+ {+ "path": "registry/default/blocks/oauth-consent-tanstack/routes/oauth/consent.tsx",+ "content": "import { createFileRoute } from '@tanstack/react-router'\n\nimport { OAuthConsent } from '@/registry/default/blocks/oauth-consent/components/oauth-consent'\n\n// This route is installed into the consumer's routes directory. Their TanStack\n// route generator adds it to FileRoutesByPath after installation.\n// @ts-expect-error The local generated route tree does not include this block route.\nexport const Route = createFileRoute('/oauth/consent')({\n component: ConsentPage,\n validateSearch: (search) => ({\n authorization_id: typeof search.authorization_id === 'string' ? search.authorization_id : null,\n }),\n})\n\nfunction ConsentPage() {\n const { authorization_id } = Route.useSearch()\n\n return (\n <main className=\"flex min-h-svh items-center justify-center p-6 md:p-10\">\n <OAuthConsent className=\"w-full max-w-lg\" authorizationId={authorization_id} />\n </main>\n )\n}\n",+ "type": "registry:file",+ "target": "routes/oauth/consent.tsx"+ },+ {+ "path": "registry/default/clients/tanstack/lib/supabase/client.ts",+ "content": "/// <reference types=\"vite/types/importMeta.d.ts\" />\nimport { createBrowserClient } from '@supabase/ssr'\n\nexport function createClient() {\n return createBrowserClient(\n import.meta.env.VITE_SUPABASE_URL!,\n import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY!\n )\n}\n",+ "type": "registry:lib"+ },+ {+ "path": "registry/default/clients/tanstack/lib/supabase/server.ts",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { getCookies, setCookie } from '@tanstack/react-start/server'\n\nexport function createClient() {\n return createServerClient(\n process.env.VITE_SUPABASE_URL!,\n process.env.VITE_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return Object.entries(getCookies()).map(\n ([name, value]) =>\n ({\n name,\n value,\n }) as { name: string; value: string }\n )\n },\n setAll(cookies) {\n cookies.forEach((cookie) => {\n setCookie(cookie.name, cookie.value)\n })\n },\n },\n }\n )\n}\n",+ "type": "registry:lib"+ }+ ],+ "envVars": {+ "VITE_SUPABASE_URL": "",+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""+ },+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` — edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```\n\nYou'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`."+}\ No newline at end of filediff --git a/apps/ui-library/public/r/password-based-auth-nextjs.json b/apps/ui-library/public/r/password-based-auth-nextjs.jsonindex 787fc6ed2f0..e4cfaeb897f 100644--- a/apps/ui-library/public/r/password-based-auth-nextjs.json+++ b/apps/ui-library/public/r/password-based-auth-nextjs.json@@ -12,7 +12,8 @@"button","card","input",- "label"+ "label",+ "https://supabase.com/library/r/safe-next-path.json"],"files": [{@@ -41,7 +42,7 @@},{"path": "registry/default/blocks/password-based-auth-nextjs/components/login-form.tsx",- "content": "'use client'\n\nimport { useRouter } from 'next/navigation'\nimport { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\nimport { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\nimport { Input } from '@/registry/default/components/ui/input'\nimport { Label } from '@/registry/default/components/ui/label'\nimport Link from 'next/link'\n\nexport function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<'div'>) {\n const [email, setEmail] = useState('')\n const [password, setPassword] = useState('')\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n const router = useRouter()\n\n const handleLogin = async (e: React.FormEvent) => {\n e.preventDefault()\n const supabase = createClient()\n setIsLoading(true)\n setError(null)\n\n try {\n const { error } = await supabase.auth.signInWithPassword({\n email,\n password,\n })\n if (error) throw error\n // Update this route to redirect to an authenticated route. The user already has an active session.\n router.push('/protected')\n } catch (error: unknown) {\n setError(error instanceof Error ? error.message : 'An error occurred')\n } finally {\n setIsLoading(false)\n }\n }\n\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Login</CardTitle>\n <CardDescription>Enter your email below to login to your account</CardDescription>\n </CardHeader>\n <CardContent>\n <form onSubmit={handleLogin}>\n <div className=\"flex flex-col gap-6\">\n <div className=\"grid gap-2\">\n <Label htmlFor=\"email\">Email</Label>\n <Input\n id=\"email\"\n type=\"email\"\n placeholder=\"[email protected]\"\n required\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n />\n </div>\n <div className=\"grid gap-2\">\n <div className=\"flex items-center\">\n <Label htmlFor=\"password\">Password</Label>\n <Link\n href=\"/auth/forgot-password\"\n className=\"ml-auto inline-block text-sm underline-offset-4 hover:underline\"\n >\n Forgot your password?\n </Link>\n </div>\n <Input\n id=\"password\"\n type=\"password\"\n required\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n />\n </div>\n {error && <p className=\"text-sm text-red-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={isLoading}>\n {isLoading ? 'Logging in...' : 'Login'}\n </Button>\n </div>\n <div className=\"mt-4 text-center text-sm\">\n Don't have an account?{' '}\n <Link href=\"/auth/sign-up\" className=\"underline underline-offset-4\">\n Sign up\n </Link>\n </div>\n </form>\n </CardContent>\n </Card>\n </div>\n )\n}\n",+ "content": "'use client'\n\nimport { useRouter } from 'next/navigation'\nimport { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\nimport { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'\nimport { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\nimport { Input } from '@/registry/default/components/ui/input'\nimport { Label } from '@/registry/default/components/ui/label'\nimport Link from 'next/link'\n\nexport function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<'div'>) {\n const [email, setEmail] = useState('')\n const [password, setPassword] = useState('')\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n const router = useRouter()\n\n const handleLogin = async (e: React.FormEvent) => {\n e.preventDefault()\n const supabase = createClient()\n setIsLoading(true)\n setError(null)\n\n try {\n const { error } = await supabase.auth.signInWithPassword({\n email,\n password,\n })\n if (error) throw error\n // Update this route to redirect to an authenticated route. The user already has an active session.\n const next = new URLSearchParams(window.location.search).get('next')\n router.push(safeNextPath(next, '/protected'))\n } catch (error: unknown) {\n setError(error instanceof Error ? error.message : 'An error occurred')\n } finally {\n setIsLoading(false)\n }\n }\n\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Login</CardTitle>\n <CardDescription>Enter your email below to login to your account</CardDescription>\n </CardHeader>\n <CardContent>\n <form onSubmit={handleLogin}>\n <div className=\"flex flex-col gap-6\">\n <div className=\"grid gap-2\">\n <Label htmlFor=\"email\">Email</Label>\n <Input\n id=\"email\"\n type=\"email\"\n placeholder=\"[email protected]\"\n required\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n />\n </div>\n <div className=\"grid gap-2\">\n <div className=\"flex items-center\">\n <Label htmlFor=\"password\">Password</Label>\n <Link\n href=\"/auth/forgot-password\"\n className=\"ml-auto inline-block text-sm underline-offset-4 hover:underline\"\n >\n Forgot your password?\n </Link>\n </div>\n <Input\n id=\"password\"\n type=\"password\"\n required\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n />\n </div>\n {error && <p className=\"text-sm text-red-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={isLoading}>\n {isLoading ? 'Logging in...' : 'Login'}\n </Button>\n </div>\n <div className=\"mt-4 text-center text-sm\">\n Don't have an account?{' '}\n <Link href=\"/auth/sign-up\" className=\"underline underline-offset-4\">\n Sign up\n </Link>\n </div>\n </form>\n </CardContent>\n </Card>\n </div>\n )\n}\n","type": "registry:component"},{@@ -101,7 +102,7 @@},{"path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",- "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n","type": "registry:lib"},{diff --git a/apps/ui-library/public/r/password-based-auth-react-router.json b/apps/ui-library/public/r/password-based-auth-react-router.jsonindex 0b3e87063b1..1474873cd46 100644--- a/apps/ui-library/public/r/password-based-auth-react-router.json+++ b/apps/ui-library/public/r/password-based-auth-react-router.json@@ -14,7 +14,8 @@"button","card","input",- "label"+ "label",+ "https://supabase.com/library/r/safe-next-path.json"],"files": [{@@ -37,7 +38,7 @@},{"path": "registry/default/blocks/password-based-auth-react-router/app/routes/login.tsx",- "content": "import { Link, redirect, useFetcher, type ActionFunctionArgs } from 'react-router'\n\nimport { createClient } from '@/registry/default/clients/react-router/lib/supabase/server'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\nimport { Input } from '@/registry/default/components/ui/input'\nimport { Label } from '@/registry/default/components/ui/label'\n\nexport const action = async ({ request }: ActionFunctionArgs) => {\n const { supabase, headers } = createClient(request)\n\n const formData = await request.formData()\n\n const email = formData.get('email') as string\n const password = formData.get('password') as string\n\n const { error } = await supabase.auth.signInWithPassword({\n email,\n password,\n })\n\n if (error) {\n return {\n error: error instanceof Error ? error.message : 'An error occurred',\n }\n }\n\n // Update this route to redirect to an authenticated route. The user already has an active session.\n return redirect('/protected', { headers })\n}\n\nexport default function Login() {\n const fetcher = useFetcher<typeof action>()\n\n const error = fetcher.data?.error\n const loading = fetcher.state === 'submitting'\n\n return (\n <div className=\"flex min-h-svh w-full items-center justify-center p-6 md:p-10\">\n <div className=\"w-full max-w-sm\">\n <div className=\"flex flex-col gap-6\">\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Login</CardTitle>\n <CardDescription>Enter your email below to login to your account</CardDescription>\n </CardHeader>\n <CardContent>\n <fetcher.Form method=\"post\">\n <div className=\"flex flex-col gap-6\">\n <div className=\"grid gap-2\">\n <Label htmlFor=\"email\">Email</Label>\n <Input\n id=\"email\"\n name=\"email\"\n type=\"email\"\n placeholder=\"[email protected]\"\n required\n />\n </div>\n <div className=\"grid gap-2\">\n <div className=\"flex items-center\">\n <Label htmlFor=\"password\">Password</Label>\n <Link\n to=\"/forgot-password\"\n className=\"ml-auto inline-block text-sm underline-offset-4 hover:underline\"\n >\n Forgot your password?\n </Link>\n </div>\n <Input id=\"password\" type=\"password\" name=\"password\" required />\n </div>\n {error && <p className=\"text-sm text-red-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={loading}>\n {loading ? 'Logging in...' : 'Login'}\n </Button>\n </div>\n <div className=\"mt-4 text-center text-sm\">\n Don't have an account?{' '}\n <Link to=\"/sign-up\" className=\"underline underline-offset-4\">\n Sign up\n </Link>\n </div>\n </fetcher.Form>\n </CardContent>\n </Card>\n </div>\n </div>\n </div>\n )\n}\n",+ "content": "import { Link, redirect, useFetcher, useSearchParams, type ActionFunctionArgs } from 'react-router'\n\nimport { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'\nimport { createClient } from '@/registry/default/clients/react-router/lib/supabase/server'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\nimport { Input } from '@/registry/default/components/ui/input'\nimport { Label } from '@/registry/default/components/ui/label'\n\nexport const action = async ({ request }: ActionFunctionArgs) => {\n const { supabase, headers } = createClient(request)\n const origin = new URL(request.url).origin\n\n const formData = await request.formData()\n\n const email = formData.get('email') as string\n const password = formData.get('password') as string\n\n const { error } = await supabase.auth.signInWithPassword({\n email,\n password,\n })\n\n if (error) {\n return {\n error: error instanceof Error ? error.message : 'An error occurred',\n }\n }\n\n // Update this route to redirect to an authenticated route. The user already has an active session.\n return redirect(safeNextPath(formData.get('next'), '/protected', origin), { headers })\n}\n\nexport default function Login() {\n const fetcher = useFetcher<typeof action>()\n const [searchParams] = useSearchParams()\n\n const error = fetcher.data?.error\n const loading = fetcher.state === 'submitting'\n\n return (\n <div className=\"flex min-h-svh w-full items-center justify-center p-6 md:p-10\">\n <div className=\"w-full max-w-sm\">\n <div className=\"flex flex-col gap-6\">\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Login</CardTitle>\n <CardDescription>Enter your email below to login to your account</CardDescription>\n </CardHeader>\n <CardContent>\n <fetcher.Form method=\"post\">\n <input type=\"hidden\" name=\"next\" value={searchParams.get('next') ?? ''} />\n <div className=\"flex flex-col gap-6\">\n <div className=\"grid gap-2\">\n <Label htmlFor=\"email\">Email</Label>\n <Input\n id=\"email\"\n name=\"email\"\n type=\"email\"\n placeholder=\"[email protected]\"\n required\n />\n </div>\n <div className=\"grid gap-2\">\n <div className=\"flex items-center\">\n <Label htmlFor=\"password\">Password</Label>\n <Link\n to=\"/forgot-password\"\n className=\"ml-auto inline-block text-sm underline-offset-4 hover:underline\"\n >\n Forgot your password?\n </Link>\n </div>\n <Input id=\"password\" type=\"password\" name=\"password\" required />\n </div>\n {error && <p className=\"text-sm text-red-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={loading}>\n {loading ? 'Logging in...' : 'Login'}\n </Button>\n </div>\n <div className=\"mt-4 text-center text-sm\">\n Don't have an account?{' '}\n <Link to=\"/sign-up\" className=\"underline underline-offset-4\">\n Sign up\n </Link>\n </div>\n </fetcher.Form>\n </CardContent>\n </Card>\n </div>\n </div>\n </div>\n )\n}\n","type": "registry:file","target": "app/routes/login.tsx"},diff --git a/apps/ui-library/public/r/password-based-auth-react.json b/apps/ui-library/public/r/password-based-auth-react.jsonindex e9cfb105d24..afe60913e02 100644--- a/apps/ui-library/public/r/password-based-auth-react.json+++ b/apps/ui-library/public/r/password-based-auth-react.json@@ -11,12 +11,13 @@"button","card","input",- "label"+ "label",+ "https://supabase.com/library/r/safe-next-path.json"],"files": [{"path": "registry/default/blocks/password-based-auth-react/components/login-form.tsx",- "content": "import { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\nimport { createClient } from '@/registry/default/clients/react/lib/supabase/client'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\nimport { Input } from '@/registry/default/components/ui/input'\nimport { Label } from '@/registry/default/components/ui/label'\n\nexport function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<'div'>) {\n const [email, setEmail] = useState('')\n const [password, setPassword] = useState('')\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n const supabase = createClient()\n\n const handleLogin = async (e: React.FormEvent) => {\n e.preventDefault()\n setIsLoading(true)\n setError(null)\n\n try {\n const { error } = await supabase.auth.signInWithPassword({\n email,\n password,\n })\n if (error) throw error\n // Update this route to redirect to an authenticated route. The user already has an active session.\n location.href = '/protected'\n } catch (error: unknown) {\n setError(error instanceof Error ? error.message : 'An error occurred')\n } finally {\n setIsLoading(false)\n }\n }\n\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Login</CardTitle>\n <CardDescription>Enter your email below to login to your account</CardDescription>\n </CardHeader>\n <CardContent>\n <form onSubmit={handleLogin}>\n <div className=\"flex flex-col gap-6\">\n <div className=\"grid gap-2\">\n <Label htmlFor=\"email\">Email</Label>\n <Input\n id=\"email\"\n type=\"email\"\n placeholder=\"[email protected]\"\n required\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n />\n </div>\n <div className=\"grid gap-2\">\n <div className=\"flex items-center\">\n <Label htmlFor=\"password\">Password</Label>\n <a\n href=\"/forgot-password\"\n className=\"ml-auto inline-block text-sm underline-offset-4 hover:underline\"\n >\n Forgot your password?\n </a>\n </div>\n <Input\n id=\"password\"\n type=\"password\"\n required\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n />\n </div>\n {error && <p className=\"text-sm text-red-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={isLoading}>\n {isLoading ? 'Logging in...' : 'Login'}\n </Button>\n </div>\n <div className=\"mt-4 text-center text-sm\">\n Don't have an account?{' '}\n <a href=\"/sign-up\" className=\"underline underline-offset-4\">\n Sign up\n </a>\n </div>\n </form>\n </CardContent>\n </Card>\n </div>\n )\n}\n",+ "content": "import { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\nimport { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'\nimport { createClient } from '@/registry/default/clients/react/lib/supabase/client'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\nimport { Input } from '@/registry/default/components/ui/input'\nimport { Label } from '@/registry/default/components/ui/label'\n\nexport function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<'div'>) {\n const [email, setEmail] = useState('')\n const [password, setPassword] = useState('')\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n const supabase = createClient()\n\n const handleLogin = async (e: React.FormEvent) => {\n e.preventDefault()\n setIsLoading(true)\n setError(null)\n\n try {\n const { error } = await supabase.auth.signInWithPassword({\n email,\n password,\n })\n if (error) throw error\n // Update this route to redirect to an authenticated route. The user already has an active session.\n const next = new URLSearchParams(window.location.search).get('next')\n location.href = safeNextPath(next, '/protected')\n } catch (error: unknown) {\n setError(error instanceof Error ? error.message : 'An error occurred')\n } finally {\n setIsLoading(false)\n }\n }\n\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Login</CardTitle>\n <CardDescription>Enter your email below to login to your account</CardDescription>\n </CardHeader>\n <CardContent>\n <form onSubmit={handleLogin}>\n <div className=\"flex flex-col gap-6\">\n <div className=\"grid gap-2\">\n <Label htmlFor=\"email\">Email</Label>\n <Input\n id=\"email\"\n type=\"email\"\n placeholder=\"[email protected]\"\n required\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n />\n </div>\n <div className=\"grid gap-2\">\n <div className=\"flex items-center\">\n <Label htmlFor=\"password\">Password</Label>\n <a\n href=\"/forgot-password\"\n className=\"ml-auto inline-block text-sm underline-offset-4 hover:underline\"\n >\n Forgot your password?\n </a>\n </div>\n <Input\n id=\"password\"\n type=\"password\"\n required\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n />\n </div>\n {error && <p className=\"text-sm text-red-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={isLoading}>\n {isLoading ? 'Logging in...' : 'Login'}\n </Button>\n </div>\n <div className=\"mt-4 text-center text-sm\">\n Don't have an account?{' '}\n <a href=\"/sign-up\" className=\"underline underline-offset-4\">\n Sign up\n </a>\n </div>\n </form>\n </CardContent>\n </Card>\n </div>\n )\n}\n","type": "registry:component"},{diff --git a/apps/ui-library/public/r/password-based-auth-tanstack.json b/apps/ui-library/public/r/password-based-auth-tanstack.jsonindex 3866d119328..209f5534c12 100644--- a/apps/ui-library/public/r/password-based-auth-tanstack.json+++ b/apps/ui-library/public/r/password-based-auth-tanstack.json@@ -12,7 +12,8 @@"button","card","input",- "label"+ "label",+ "https://supabase.com/library/r/safe-next-path.json"],"files": [{@@ -47,7 +48,7 @@},{"path": "registry/default/blocks/password-based-auth-tanstack/components/login-form.tsx",- "content": "import { Link, useNavigate } from '@tanstack/react-router'\nimport { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\nimport { createClient } from '@/registry/default/clients/tanstack/lib/supabase/client'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\nimport { Input } from '@/registry/default/components/ui/input'\nimport { Label } from '@/registry/default/components/ui/label'\n\nexport function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<'div'>) {\n const [email, setEmail] = useState('')\n const [password, setPassword] = useState('')\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n const navigate = useNavigate()\n\n const handleLogin = async (e: React.FormEvent) => {\n e.preventDefault()\n const supabase = createClient()\n setIsLoading(true)\n setError(null)\n\n try {\n const { error } = await supabase.auth.signInWithPassword({\n email,\n password,\n })\n if (error) throw error\n // Update this route to redirect to an authenticated route. The user already has an active session.\n await navigate({ to: '/protected' })\n } catch (error: unknown) {\n setError(error instanceof Error ? error.message : 'An error occurred')\n } finally {\n setIsLoading(false)\n }\n }\n\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Login</CardTitle>\n <CardDescription>Enter your email below to login to your account</CardDescription>\n </CardHeader>\n <CardContent>\n <form onSubmit={handleLogin}>\n <div className=\"flex flex-col gap-6\">\n <div className=\"grid gap-2\">\n <Label htmlFor=\"email\">Email</Label>\n <Input\n id=\"email\"\n type=\"email\"\n placeholder=\"[email protected]\"\n required\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n />\n </div>\n <div className=\"grid gap-2\">\n <div className=\"flex items-center\">\n <Label htmlFor=\"password\">Password</Label>\n <Link\n to=\"/forgot-password\"\n className=\"ml-auto inline-block text-sm underline-offset-4 hover:underline\"\n >\n Forgot your password?\n </Link>\n </div>\n <Input\n id=\"password\"\n type=\"password\"\n required\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n />\n </div>\n {error && <p className=\"text-sm text-red-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={isLoading}>\n {isLoading ? 'Logging in...' : 'Login'}\n </Button>\n </div>\n <div className=\"mt-4 text-center text-sm\">\n Don't have an account?{' '}\n <Link to=\"/sign-up\" className=\"underline underline-offset-4\">\n Sign up\n </Link>\n </div>\n </form>\n </CardContent>\n </Card>\n </div>\n )\n}\n",+ "content": "import { Link } from '@tanstack/react-router'\nimport { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\nimport { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'\nimport { createClient } from '@/registry/default/clients/tanstack/lib/supabase/client'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\nimport { Input } from '@/registry/default/components/ui/input'\nimport { Label } from '@/registry/default/components/ui/label'\n\nexport function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<'div'>) {\n const [email, setEmail] = useState('')\n const [password, setPassword] = useState('')\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n\n const handleLogin = async (e: React.FormEvent) => {\n e.preventDefault()\n const supabase = createClient()\n setIsLoading(true)\n setError(null)\n\n try {\n const { error } = await supabase.auth.signInWithPassword({\n email,\n password,\n })\n if (error) throw error\n // Follow the `next` query parameter if it is a same-origin relative path, e.g. when\n // the OAuth consent screen sent the user here to sign in first. It may point outside\n // the typed route tree, so it needs a full navigation.\n const next = new URLSearchParams(window.location.search).get('next')\n window.location.assign(safeNextPath(next, '/protected'))\n } catch (error: unknown) {\n setError(error instanceof Error ? error.message : 'An error occurred')\n } finally {\n setIsLoading(false)\n }\n }\n\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Login</CardTitle>\n <CardDescription>Enter your email below to login to your account</CardDescription>\n </CardHeader>\n <CardContent>\n <form onSubmit={handleLogin}>\n <div className=\"flex flex-col gap-6\">\n <div className=\"grid gap-2\">\n <Label htmlFor=\"email\">Email</Label>\n <Input\n id=\"email\"\n type=\"email\"\n placeholder=\"[email protected]\"\n required\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n />\n </div>\n <div className=\"grid gap-2\">\n <div className=\"flex items-center\">\n <Label htmlFor=\"password\">Password</Label>\n <Link\n to=\"/forgot-password\"\n className=\"ml-auto inline-block text-sm underline-offset-4 hover:underline\"\n >\n Forgot your password?\n </Link>\n </div>\n <Input\n id=\"password\"\n type=\"password\"\n required\n value={password}\n onChange={(e) => setPassword(e.target.value)}\n />\n </div>\n {error && <p className=\"text-sm text-red-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={isLoading}>\n {isLoading ? 'Logging in...' : 'Login'}\n </Button>\n </div>\n <div className=\"mt-4 text-center text-sm\">\n Don't have an account?{' '}\n <Link to=\"/sign-up\" className=\"underline underline-offset-4\">\n Sign up\n </Link>\n </div>\n </form>\n </CardContent>\n </Card>\n </div>\n )\n}\n","type": "registry:component"},{diff --git a/apps/ui-library/public/r/platform-kit-nextjs.json b/apps/ui-library/public/r/platform-kit-nextjs.jsonindex 3cb976b10c3..32389fd3e05 100644--- a/apps/ui-library/public/r/platform-kit-nextjs.json+++ b/apps/ui-library/public/r/platform-kit-nextjs.json@@ -86,7 +86,7 @@},{"path": "registry/default/platform/platform-kit-nextjs/components/supabase-manager/index.tsx",- "content": "'use client'\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query'\nimport {\n ChevronLeft,\n ChevronRight,\n Database,\n ExternalLink,\n HardDrive,\n KeyRound,\n Lightbulb,\n ScrollText,\n Shield,\n Users,\n} from 'lucide-react'\nimport Link from 'next/link'\nimport { ReactNode, useMemo, useState } from 'react'\n\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Dialog,\n DialogContent,\n DialogTitle,\n DialogTrigger,\n} from '@/registry/default/components/ui/dialog'\nimport {\n Drawer,\n DrawerContent,\n DrawerHeader,\n DrawerTitle,\n} from '@/registry/default/components/ui/drawer'\nimport {\n HoverCard,\n HoverCardContent,\n HoverCardTrigger,\n} from '@/registry/default/components/ui/hover-card'\nimport { LogoSupabase } from '@/registry/default/platform/platform-kit-nextjs/components/logo-supabase'\nimport { AuthManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/auth'\nimport { DatabaseManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/database'\nimport { LogsManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/logs'\nimport { SecretsManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/secrets'\nimport { StorageManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/storage'\nimport { SuggestionsManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/suggestions'\nimport { UsersManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/users'\nimport {\n SheetNavigationProvider,\n useSheetNavigation,\n} from '@/registry/default/platform/platform-kit-nextjs/contexts/SheetNavigationContext'\n\nconst queryClient = new QueryClient()\n\nfunction DialogView({ projectRef, isMobile }: { projectRef: string; isMobile?: boolean }) {\n const { stack, push, popTo, reset } = useSheetNavigation()\n\n const handleTopLevelNavigation = (title: string, component: ReactNode) => {\n if (stack.length === 1 && stack[0].title === title) {\n return\n }\n reset()\n push({ title, component })\n }\n\n const currentView = stack[stack.length - 1]\n const activeManager = stack.length > 0 ? stack[0].title : null\n\n const navigationItems = useMemo(\n () => [\n {\n title: 'Database',\n icon: Database,\n component: <DatabaseManager projectRef={projectRef} />,\n },\n {\n title: 'Storage',\n icon: HardDrive,\n component: <StorageManager projectRef={projectRef} />,\n },\n {\n title: 'Auth',\n icon: Shield,\n component: <AuthManager projectRef={projectRef} />,\n },\n {\n title: 'Users',\n icon: Users,\n component: <UsersManager projectRef={projectRef} />,\n },\n {\n title: 'Secrets',\n icon: KeyRound,\n component: <SecretsManager projectRef={projectRef} />,\n },\n {\n title: 'Logs',\n icon: ScrollText,\n component: <LogsManager projectRef={projectRef} />,\n },\n {\n title: 'Suggestions',\n icon: Lightbulb,\n component: <SuggestionsManager projectRef={projectRef} />,\n },\n ],\n [projectRef]\n )\n\n if (isMobile) {\n return (\n <div className=\"flex flex-col h-full overflow-hidden\">\n {/* Content Area */}\n <div className=\"flex flex-col overflow-hidden h-full\">\n <div className=\"grow overflow-y-auto\">\n {currentView ? (\n currentView.component\n ) : (\n <div className=\"flex items-center justify-center h-full\">\n <p className=\"text-muted-foreground\">\n Select a manager from the bottom navigation to get started.\n </p>\n </div>\n )}\n </div>\n </div>\n\n {/* Bottom Navigation Bar */}\n <div className=\"border-t bg-background\">\n <div className=\"overflow-x-auto\">\n <div className=\"flex gap-1 p-2 min-w-max\">\n {navigationItems.map((item) => {\n const Icon = item.icon\n return (\n <Button\n key={item.title}\n variant={activeManager === item.title ? 'secondary' : 'ghost'}\n className=\"flex-col h-16 w-20 min-w-16 text-xs gap-1 px-2\"\n onClick={() => handleTopLevelNavigation(item.title, item.component)}\n >\n <Icon className=\"h-5 w-5\" />\n <span className=\"text-[10px] leading-tight text-center\">\n {item.title === 'Auth' ? 'Auth' : item.title}\n </span>\n </Button>\n )\n })}\n </div>\n </div>\n </div>\n </div>\n )\n }\n\n return (\n <div className=\"grid grid-cols-[240px_1fr] h-full overflow-hidden\">\n {/* Sidebar */}\n <div className=\"flex flex-col border-r px-3 py-6 pb-3\">\n <div className=\"px-4 mb-4\">\n <h2 className=\"text-muted-foreground font-semibold text-sm\">Manage your back-end</h2>\n </div>\n <div className=\"grow space-y-0.5\">\n {navigationItems.map((item) => {\n const Icon = item.icon\n return (\n <Button\n key={item.title}\n variant={activeManager === item.title ? 'secondary' : 'ghost'}\n className=\"w-full justify-start text-sm\"\n onClick={() => handleTopLevelNavigation(item.title, item.component)}\n >\n <Icon className=\"mr-2 text-muted-foreground\" />\n {item.title === 'Auth' ? 'Authentication' : item.title}\n </Button>\n )\n })}\n </div>\n <footer className=\"p-0 text-sm text-muted-foreground flex items-center gap-3 -m-3 border-t\">\n <HoverCard>\n <HoverCardTrigger asChild>\n <Link\n href={`https://supabase.com/dashboard/project/${projectRef}`}\n target=\"_blank\"\n className=\"flex items-center px-4 w-full rounded-none text-sm py-4 h-auto justify-start gap-3 text-sm text-left hover:bg-accent\"\n >\n <LogoSupabase size={16} />\n <span className=\"flex-1\">Open in Supabase</span>\n <ExternalLink className=\"ml-2 h-4 w-4 text-muted-foreground/50\" />\n </Link>\n </HoverCardTrigger>\n <HoverCardContent\n sideOffset={8}\n align=\"start\"\n side=\"top\"\n className=\"text-sm bg-muted/50 w-[216px]\"\n >\n <h4 className=\"font-semibold mb-1\">About Supabase</h4>\n <p className=\"text-muted-foreground\">\n Access powerful back-end tools for database, auth, storage, and logs directly in\n Supabase.\n </p>\n </HoverCardContent>\n </HoverCard>\n </footer>\n </div>\n\n {/* Content Area */}\n <div className=\"flex flex-col overflow-hidden h-full\">\n {/* Header with breadcrumbs */}\n <div className=\"flex items-center h-12 shrink-0 px-4 relative border-b\">\n {stack.length > 1 && (\n <Button\n variant=\"outline\"\n size=\"icon\"\n className=\"h-8 w-8 relative z-10\"\n onClick={() => popTo(stack.length - 2)}\n >\n <ChevronLeft className=\"h-4 w-4\" />\n <span className=\"sr-only\">Back</span>\n </Button>\n )}\n {/* Breadcrumbs */}\n <div className=\"ml-4 flex items-center gap-1.5 text-sm text-muted-foreground relative z-10\">\n {stack.map((item: { title: string }, index: number) => (\n <div key={`${item.title}-${index}`} className=\"flex items-center gap-1.5\">\n {index > 0 && <ChevronRight className=\"h-3 w-3\" />}\n {index === stack.length - 1 ? (\n <span className=\"font-semibold text-foreground\">{item.title}</span>\n ) : (\n <button onClick={() => popTo(index)} className=\"hover:underline\">\n {item.title}\n </button>\n )}\n </div>\n ))}\n </div>\n </div>\n\n <div className=\"grow overflow-y-auto\">\n {currentView ? (\n currentView.component\n ) : (\n <div className=\"flex items-center justify-center h-full\">\n <p className=\"text-muted-foreground\">\n Select a manager from the sidebar to get started.\n </p>\n </div>\n )}\n </div>\n </div>\n </div>\n )\n}\n\nexport default function SupabaseManagerDialog({\n projectRef,\n open,\n onOpenChange,\n isMobile,\n}: {\n projectRef: string\n open: boolean\n onOpenChange: (open: boolean) => void\n isMobile: boolean\n}) {\n const content = (\n <SheetNavigationProvider\n onStackEmpty={() => {}}\n initialStack={[\n {\n title: 'Database',\n component: <DatabaseManager projectRef={projectRef} />,\n },\n ]}\n >\n <DialogView projectRef={projectRef} isMobile={isMobile} />\n </SheetNavigationProvider>\n )\n\n if (!isMobile) {\n return (\n <QueryClientProvider client={queryClient}>\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent className=\"w-full h-[80vh] max-h-[700px] sm:max-w-[calc(100%-2rem)] w-[1180px] p-0 overflow-hidden sm:rounded-lg\">\n <DialogTitle className=\"sr-only\">Manage your back-end</DialogTitle>\n {content}\n </DialogContent>\n </Dialog>\n </QueryClientProvider>\n )\n }\n\n return (\n <QueryClientProvider client={queryClient}>\n <Drawer open={open} onOpenChange={onOpenChange}>\n <DrawerContent className=\"h-[90vh] p-0 overflow-hidden\">\n <DrawerHeader className=\"sr-only\">\n <DrawerTitle>Manage your back-end</DrawerTitle>\n </DrawerHeader>\n {content}\n </DrawerContent>\n </Drawer>\n </QueryClientProvider>\n )\n}\n",+ "content": "'use client'\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query'\nimport {\n ChevronLeft,\n ChevronRight,\n Database,\n ExternalLink,\n HardDrive,\n KeyRound,\n Lightbulb,\n ScrollText,\n Shield,\n Users,\n} from 'lucide-react'\nimport Link from 'next/link'\nimport { ReactNode, useMemo, useState } from 'react'\n\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Dialog,\n DialogContent,\n DialogTitle,\n DialogTrigger,\n} from '@/registry/default/components/ui/dialog'\nimport {\n Drawer,\n DrawerContent,\n DrawerHeader,\n DrawerTitle,\n} from '@/registry/default/components/ui/drawer'\nimport {\n HoverCard,\n HoverCardContent,\n HoverCardTrigger,\n} from '@/registry/default/components/ui/hover-card'\nimport { LogoSupabase } from '@/registry/default/platform/platform-kit-nextjs/components/logo-supabase'\nimport { AuthManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/auth'\nimport { DatabaseManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/database'\nimport { LogsManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/logs'\nimport { SecretsManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/secrets'\nimport { StorageManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/storage'\nimport { SuggestionsManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/suggestions'\nimport { UsersManager } from '@/registry/default/platform/platform-kit-nextjs/components/supabase-manager/users'\nimport {\n SheetNavigationProvider,\n useSheetNavigation,\n} from '@/registry/default/platform/platform-kit-nextjs/contexts/SheetNavigationContext'\n\nconst queryClient = new QueryClient()\n\nfunction DialogView({ projectRef, isMobile }: { projectRef: string; isMobile?: boolean }) {\n const { stack, push, popTo, reset } = useSheetNavigation()\n\n const handleTopLevelNavigation = (title: string, component: ReactNode) => {\n if (stack.length === 1 && stack[0].title === title) {\n return\n }\n reset()\n push({ title, component })\n }\n\n const currentView = stack[stack.length - 1]\n const activeManager = stack.length > 0 ? stack[0].title : null\n\n const navigationItems = useMemo(\n () => [\n {\n title: 'Database',\n icon: Database,\n component: <DatabaseManager projectRef={projectRef} />,\n },\n {\n title: 'Storage',\n icon: HardDrive,\n component: <StorageManager projectRef={projectRef} />,\n },\n {\n title: 'Auth',\n icon: Shield,\n component: <AuthManager projectRef={projectRef} />,\n },\n {\n title: 'Users',\n icon: Users,\n component: <UsersManager projectRef={projectRef} />,\n },\n {\n title: 'Secrets',\n icon: KeyRound,\n component: <SecretsManager projectRef={projectRef} />,\n },\n {\n title: 'Logs',\n icon: ScrollText,\n component: <LogsManager projectRef={projectRef} />,\n },\n {\n title: 'Suggestions',\n icon: Lightbulb,\n component: <SuggestionsManager projectRef={projectRef} />,\n },\n ],\n [projectRef]\n )\n\n if (isMobile) {\n return (\n <div className=\"flex flex-col h-full overflow-hidden\">\n {/* Content Area */}\n <div className=\"flex flex-col overflow-hidden h-full\">\n <div className=\"grow overflow-y-auto\">\n {currentView ? (\n currentView.component\n ) : (\n <div className=\"flex items-center justify-center h-full\">\n <p className=\"text-muted-foreground\">\n Select a manager from the bottom navigation to get started.\n </p>\n </div>\n )}\n </div>\n </div>\n\n {/* Bottom Navigation Bar */}\n <div className=\"border-t bg-background\">\n <div className=\"overflow-x-auto\">\n <div className=\"flex gap-1 p-2 min-w-max\">\n {navigationItems.map((item) => {\n const Icon = item.icon\n return (\n <Button\n key={item.title}\n variant={activeManager === item.title ? 'secondary' : 'ghost'}\n className=\"flex-col h-16 w-20 min-w-16 text-xs gap-1 px-2\"\n onClick={() => handleTopLevelNavigation(item.title, item.component)}\n >\n <Icon className=\"h-5 w-5\" />\n <span className=\"text-[10px] leading-tight text-center\">\n {item.title === 'Auth' ? 'Auth' : item.title}\n </span>\n </Button>\n )\n })}\n </div>\n </div>\n </div>\n </div>\n )\n }\n\n return (\n <div className=\"grid grid-cols-[240px_1fr] h-full overflow-hidden\">\n {/* Sidebar */}\n <div className=\"flex flex-col border-r px-3 py-6 pb-3\">\n <div className=\"px-4 mb-4\">\n <h2 className=\"text-muted-foreground font-semibold text-sm\">Manage your back-end</h2>\n </div>\n <div className=\"grow space-y-0.5\">\n {navigationItems.map((item) => {\n const Icon = item.icon\n return (\n <Button\n key={item.title}\n variant={activeManager === item.title ? 'secondary' : 'ghost'}\n className=\"w-full justify-start text-sm\"\n onClick={() => handleTopLevelNavigation(item.title, item.component)}\n >\n <Icon className=\"mr-2 text-muted-foreground\" />\n {item.title === 'Auth' ? 'Authentication' : item.title}\n </Button>\n )\n })}\n </div>\n <footer className=\"p-0 text-sm text-muted-foreground flex items-center gap-3 -m-3 border-t\">\n <HoverCard>\n <HoverCardTrigger asChild>\n <Link\n href={`https://supabase.com/dashboard/project/${projectRef}`}\n target=\"_blank\"\n className=\"flex items-center px-4 w-full rounded-none text-sm py-4 h-auto justify-start gap-3 text-sm text-left hover:bg-accent\"\n >\n <LogoSupabase size={16} />\n <span className=\"flex-1\">Open in Supabase</span>\n <ExternalLink className=\"ml-2 h-4 w-4 text-muted-foreground/50\" />\n </Link>\n </HoverCardTrigger>\n <HoverCardContent\n sideOffset={8}\n align=\"start\"\n side=\"top\"\n className=\"text-sm bg-muted/50 w-[216px]\"\n >\n <h4 className=\"font-semibold mb-1\">About Supabase</h4>\n <p className=\"text-muted-foreground\">\n Access powerful back-end tools for database, auth, storage, and logs directly in\n Supabase.\n </p>\n </HoverCardContent>\n </HoverCard>\n </footer>\n </div>\n\n {/* Content Area */}\n <div className=\"flex flex-col overflow-hidden h-full\">\n {/* Header with breadcrumbs */}\n <div className=\"flex items-center h-12 shrink-0 px-4 relative border-b\">\n {stack.length > 1 && (\n <Button\n variant=\"outline\"\n size=\"icon\"\n className=\"h-8 w-8 relative z-10\"\n onClick={() => popTo(stack.length - 2)}\n >\n <ChevronLeft className=\"h-4 w-4\" />\n <span className=\"sr-only\">Back</span>\n </Button>\n )}\n {/* Breadcrumbs */}\n <div className=\"ml-4 flex items-center gap-1.5 text-sm text-muted-foreground relative z-10\">\n {stack.map((item: { title: string }, index: number) => (\n <div key={`${item.title}-${index}`} className=\"flex items-center gap-1.5\">\n {index > 0 && <ChevronRight className=\"h-3 w-3\" />}\n {index === stack.length - 1 ? (\n <span className=\"font-semibold text-foreground\">{item.title}</span>\n ) : (\n <button\n type=\"button\"\n tabIndex={0}\n onClick={() => popTo(index)}\n className=\"hover:underline\"\n >\n {item.title}\n </button>\n )}\n </div>\n ))}\n </div>\n </div>\n\n <div className=\"grow overflow-y-auto\">\n {currentView ? (\n currentView.component\n ) : (\n <div className=\"flex items-center justify-center h-full\">\n <p className=\"text-muted-foreground\">\n Select a manager from the sidebar to get started.\n </p>\n </div>\n )}\n </div>\n </div>\n </div>\n )\n}\n\nexport default function SupabaseManagerDialog({\n projectRef,\n open,\n onOpenChange,\n isMobile,\n}: {\n projectRef: string\n open: boolean\n onOpenChange: (open: boolean) => void\n isMobile: boolean\n}) {\n const content = (\n <SheetNavigationProvider\n onStackEmpty={() => {}}\n initialStack={[\n {\n title: 'Database',\n component: <DatabaseManager projectRef={projectRef} />,\n },\n ]}\n >\n <DialogView projectRef={projectRef} isMobile={isMobile} />\n </SheetNavigationProvider>\n )\n\n if (!isMobile) {\n return (\n <QueryClientProvider client={queryClient}>\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent className=\"w-full h-[80vh] max-h-[700px] sm:max-w-[calc(100%-2rem)] w-[1180px] p-0 overflow-hidden sm:rounded-lg\">\n <DialogTitle className=\"sr-only\">Manage your back-end</DialogTitle>\n {content}\n </DialogContent>\n </Dialog>\n </QueryClientProvider>\n )\n }\n\n return (\n <QueryClientProvider client={queryClient}>\n <Drawer open={open} onOpenChange={onOpenChange}>\n <DrawerContent className=\"h-[90vh] p-0 overflow-hidden\">\n <DrawerHeader className=\"sr-only\">\n <DrawerTitle>Manage your back-end</DrawerTitle>\n </DrawerHeader>\n {content}\n </DrawerContent>\n </Drawer>\n </QueryClientProvider>\n )\n}\n","type": "registry:component"},{diff --git a/apps/ui-library/public/r/realtime-avatar-stack-nextjs.json b/apps/ui-library/public/r/realtime-avatar-stack-nextjs.jsonindex dfbca00e999..2338c698d3d 100644--- a/apps/ui-library/public/r/realtime-avatar-stack-nextjs.json+++ b/apps/ui-library/public/r/realtime-avatar-stack-nextjs.json@@ -45,7 +45,7 @@},{"path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",- "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n","type": "registry:lib"},{diff --git a/apps/ui-library/public/r/realtime-chat-nextjs.json b/apps/ui-library/public/r/realtime-chat-nextjs.jsonindex 72385d8c17f..43b0298b6e4 100644--- a/apps/ui-library/public/r/realtime-chat-nextjs.json+++ b/apps/ui-library/public/r/realtime-chat-nextjs.json@@ -41,7 +41,7 @@},{"path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",- "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n","type": "registry:lib"},{diff --git a/apps/ui-library/public/r/realtime-cursor-nextjs.json b/apps/ui-library/public/r/realtime-cursor-nextjs.jsonindex 10d19899a20..06ee4bd35f8 100644--- a/apps/ui-library/public/r/realtime-cursor-nextjs.json+++ b/apps/ui-library/public/r/realtime-cursor-nextjs.json@@ -33,7 +33,7 @@},{"path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",- "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n","type": "registry:lib"},{diff --git a/apps/ui-library/public/r/realtime-flow-nextjs.json b/apps/ui-library/public/r/realtime-flow-nextjs.jsonindex 7249b12d55a..58a4f65ccc9 100644--- a/apps/ui-library/public/r/realtime-flow-nextjs.json+++ b/apps/ui-library/public/r/realtime-flow-nextjs.json@@ -31,7 +31,7 @@},{"path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",- "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n","type": "registry:lib"},{diff --git a/apps/ui-library/public/r/realtime-monaco-nextjs.json b/apps/ui-library/public/r/realtime-monaco-nextjs.jsonindex cf141d4690b..11d0760c1ee 100644--- a/apps/ui-library/public/r/realtime-monaco-nextjs.json+++ b/apps/ui-library/public/r/realtime-monaco-nextjs.json@@ -30,7 +30,7 @@},{"path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",- "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n","type": "registry:lib"},{diff --git a/apps/ui-library/public/r/registry.json b/apps/ui-library/public/r/registry.jsonindex 6968fddc64a..4afb6f79ca5 100644--- a/apps/ui-library/public/r/registry.json+++ b/apps/ui-library/public/r/registry.json@@ -3,6 +3,22 @@"name": "Supabase Library","homepage": "https://supabase.com/library","items": [+ {+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "safe-next-path",+ "type": "registry:lib",+ "title": "Safe next path",+ "description": "Validates same-origin paths before redirecting.",+ "registryDependencies": [],+ "dependencies": [],+ "files": [+ {+ "path": "registry/default/blocks/safe-next-path/lib/safe-next-path.ts",+ "type": "registry:lib",+ "target": "lib/safe-next-path.ts"+ }+ ]+ },{"name": "password-based-auth-nextjs","type": "registry:block",@@ -12,7 +28,8 @@"button","card","input",- "label"+ "label",+ "https://supabase.com/library/r/safe-next-path.json"],"dependencies": ["@supabase/ssr@latest",@@ -112,7 +129,8 @@"button","card","input",- "label"+ "label",+ "https://supabase.com/library/r/safe-next-path.json"],"files": [{@@ -154,7 +172,8 @@"button","card","input",- "label"+ "label",+ "https://supabase.com/library/r/safe-next-path.json"],"dependencies": ["@supabase/ssr@latest",@@ -232,7 +251,8 @@"button","card","input",- "label"+ "label",+ "https://supabase.com/library/r/safe-next-path.json"],"dependencies": ["@supabase/ssr@latest",@@ -326,7 +346,8 @@"description": "Social Auth flow for Nextjs and Supabase","registryDependencies": ["button",- "card"+ "card",+ "https://supabase.com/library/r/safe-next-path.json"],"dependencies": ["@supabase/ssr@latest",@@ -420,7 +441,8 @@"description": "Social Auth flow for React Router and Supabase","registryDependencies": ["button",- "card"+ "card",+ "https://supabase.com/library/r/safe-next-path.json"],"dependencies": ["@supabase/ssr@latest",@@ -481,7 +503,8 @@"description": "Social Auth flow for TanStack and Supabase","registryDependencies": ["button",- "card"+ "card",+ "https://supabase.com/library/r/safe-next-path.json"],"dependencies": ["@supabase/ssr@latest",@@ -1723,6 +1746,172 @@}]},+ {+ "name": "oauth-consent-nextjs",+ "type": "registry:block",+ "title": "OAuth Consent for Next.js",+ "description": "OAuth 2.1 consent screen and route for an existing authenticated application.",+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` — edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```\n\nYou'll need to set the following environment variables in your project: `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY`.",+ "registryDependencies": [+ "button",+ "card",+ "https://supabase.com/library/r/safe-next-path.json"+ ],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "type": "registry:hook"+ },+ {+ "path": "registry/default/blocks/oauth-consent-nextjs/app/oauth/consent/page.tsx",+ "type": "registry:page",+ "target": "app/oauth/consent/page.tsx"+ },+ {+ "path": "registry/default/clients/nextjs/lib/supabase/client.ts",+ "type": "registry:lib"+ },+ {+ "path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",+ "type": "registry:lib"+ },+ {+ "path": "registry/default/clients/nextjs/lib/supabase/server.ts",+ "type": "registry:lib"+ }+ ],+ "dependencies": [+ "@supabase/ssr@latest",+ "@supabase/supabase-js@latest"+ ],+ "envVars": {+ "NEXT_PUBLIC_SUPABASE_URL": "",+ "NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY": ""+ }+ },+ {+ "name": "oauth-consent-react",+ "type": "registry:block",+ "title": "OAuth Consent for React",+ "description": "OAuth 2.1 consent component for an existing authenticated application.",+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` — edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```\n\nYou'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`.",+ "registryDependencies": [+ "button",+ "card",+ "https://supabase.com/library/r/safe-next-path.json"+ ],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "type": "registry:hook"+ },+ {+ "path": "registry/default/clients/react/lib/supabase/client.ts",+ "type": "registry:lib"+ }+ ],+ "dependencies": [+ "@supabase/supabase-js@latest"+ ],+ "envVars": {+ "VITE_SUPABASE_URL": "",+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""+ }+ },+ {+ "name": "oauth-consent-react-router",+ "type": "registry:block",+ "title": "OAuth Consent for React Router",+ "description": "OAuth 2.1 consent screen and route for an existing authenticated application.",+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` — edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```\n\nYou'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`.",+ "registryDependencies": [+ "button",+ "card",+ "https://supabase.com/library/r/safe-next-path.json"+ ],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "type": "registry:hook"+ },+ {+ "path": "registry/default/blocks/oauth-consent-react-router/app/routes/oauth.consent.tsx",+ "type": "registry:file",+ "target": "app/routes/oauth.consent.tsx"+ },+ {+ "path": "registry/default/clients/react-router/lib/supabase/client.ts",+ "type": "registry:lib"+ },+ {+ "path": "registry/default/clients/react-router/lib/supabase/server.ts",+ "type": "registry:lib"+ }+ ],+ "dependencies": [+ "@supabase/ssr@latest",+ "@supabase/supabase-js@latest"+ ],+ "envVars": {+ "VITE_SUPABASE_URL": "",+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""+ }+ },+ {+ "name": "oauth-consent-tanstack",+ "type": "registry:block",+ "title": "OAuth Consent for TanStack Start",+ "description": "OAuth 2.1 consent screen and route for an existing authenticated application.",+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` — edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```\n\nYou'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`.",+ "registryDependencies": [+ "button",+ "card",+ "https://supabase.com/library/r/safe-next-path.json"+ ],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "type": "registry:hook"+ },+ {+ "path": "registry/default/blocks/oauth-consent-tanstack/routes/oauth/consent.tsx",+ "type": "registry:file",+ "target": "routes/oauth/consent.tsx"+ },+ {+ "path": "registry/default/clients/tanstack/lib/supabase/client.ts",+ "type": "registry:lib"+ },+ {+ "path": "registry/default/clients/tanstack/lib/supabase/server.ts",+ "type": "registry:lib"+ }+ ],+ "dependencies": [+ "@supabase/ssr@latest",+ "@supabase/supabase-js@latest"+ ],+ "envVars": {+ "VITE_SUPABASE_URL": "",+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""+ }+ },{"$schema": "https://ui.shadcn.com/schema/registry-item.json","name": "tanstack-db-nextjs",@@ -2651,4 +2840,4 @@]}]-}+}\ No newline at end of filediff --git a/apps/ui-library/public/r/safe-next-path.json b/apps/ui-library/public/r/safe-next-path.jsonnew file mode 100644index 00000000000..441364e56d0--- /dev/null+++ b/apps/ui-library/public/r/safe-next-path.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "safe-next-path",+ "type": "registry:lib",+ "title": "Safe next path",+ "description": "Validates same-origin paths before redirecting.",+ "dependencies": [],+ "registryDependencies": [],+ "files": [+ {+ "path": "registry/default/blocks/safe-next-path/lib/safe-next-path.ts",+ "content": "export const safeNextPath = (path: unknown, fallback = '/', origin?: string) => {\n if (typeof path !== 'string' || !path.startsWith('/')) return fallback\n\n const currentOrigin = origin ?? window.location.origin\n\n try {\n const url = new URL(path, currentOrigin)\n return url.origin === currentOrigin ? `${url.pathname}${url.search}${url.hash}` : fallback\n } catch {\n return fallback\n }\n}\n",+ "type": "registry:lib",+ "target": "lib/safe-next-path.ts"+ }+ ]+}\ No newline at end of filediff --git a/apps/ui-library/public/r/social-auth-nextjs.json b/apps/ui-library/public/r/social-auth-nextjs.jsonindex 6463dd1b85e..a49a2280c0e 100644--- a/apps/ui-library/public/r/social-auth-nextjs.json+++ b/apps/ui-library/public/r/social-auth-nextjs.json@@ -10,7 +10,8 @@],"registryDependencies": ["button",- "card"+ "card",+ "https://supabase.com/library/r/safe-next-path.json"],"files": [{@@ -39,7 +40,7 @@},{"path": "registry/default/blocks/social-auth-nextjs/components/login-form.tsx",- "content": "'use client'\n\nimport { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\nimport { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\n\nexport function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<'div'>) {\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n\n const handleSocialLogin = async (e: React.FormEvent) => {\n e.preventDefault()\n const supabase = createClient()\n setIsLoading(true)\n setError(null)\n\n try {\n const { error } = await supabase.auth.signInWithOAuth({\n provider: 'github',\n options: {\n redirectTo: `${window.location.origin}/auth/oauth?next=/protected`,\n },\n })\n\n if (error) throw error\n } catch (error: unknown) {\n setError(error instanceof Error ? error.message : 'An error occurred')\n setIsLoading(false)\n }\n }\n\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Welcome!</CardTitle>\n <CardDescription>Sign in to your account to continue</CardDescription>\n </CardHeader>\n <CardContent>\n <form onSubmit={handleSocialLogin}>\n <div className=\"flex flex-col gap-6\">\n {error && <p className=\"text-sm text-destructive-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={isLoading}>\n {isLoading ? 'Logging in...' : 'Continue with GitHub'}\n </Button>\n </div>\n </form>\n </CardContent>\n </Card>\n </div>\n )\n}\n",+ "content": "'use client'\n\nimport { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\nimport { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'\nimport { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\n\nexport function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<'div'>) {\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n\n const handleSocialLogin = async (e: React.FormEvent) => {\n e.preventDefault()\n const supabase = createClient()\n setIsLoading(true)\n setError(null)\n\n try {\n const next = new URLSearchParams(window.location.search).get('next')\n const { error } = await supabase.auth.signInWithOAuth({\n provider: 'github',\n options: {\n redirectTo: `${window.location.origin}/auth/oauth?next=${encodeURIComponent(safeNextPath(next, '/protected'))}`,\n },\n })\n\n if (error) throw error\n } catch (error: unknown) {\n setError(error instanceof Error ? error.message : 'An error occurred')\n setIsLoading(false)\n }\n }\n\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Welcome!</CardTitle>\n <CardDescription>Sign in to your account to continue</CardDescription>\n </CardHeader>\n <CardContent>\n <form onSubmit={handleSocialLogin}>\n <div className=\"flex flex-col gap-6\">\n {error && <p className=\"text-sm text-destructive-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={isLoading}>\n {isLoading ? 'Logging in...' : 'Continue with GitHub'}\n </Button>\n </div>\n </form>\n </CardContent>\n </Card>\n </div>\n )\n}\n","type": "registry:component"},{@@ -60,7 +61,7 @@},{"path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",- "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n","type": "registry:lib"},{diff --git a/apps/ui-library/public/r/social-auth-react-router.json b/apps/ui-library/public/r/social-auth-react-router.jsonindex b6d80cfa459..3956d8fe86b 100644--- a/apps/ui-library/public/r/social-auth-react-router.json+++ b/apps/ui-library/public/r/social-auth-react-router.json@@ -12,7 +12,8 @@],"registryDependencies": ["button",- "card"+ "card",+ "https://supabase.com/library/r/safe-next-path.json"],"files": [{@@ -29,7 +30,7 @@},{"path": "registry/default/blocks/social-auth-react-router/app/routes/login.tsx",- "content": "import { redirect, useFetcher, type ActionFunctionArgs } from 'react-router'\n\nimport { createClient } from '@/registry/default/clients/react-router/lib/supabase/server'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\n\nexport const action = async ({ request }: ActionFunctionArgs) => {\n const { supabase } = createClient(request)\n const origin = new URL(request.url).origin\n\n const { data, error } = await supabase.auth.signInWithOAuth({\n provider: 'github',\n options: {\n redirectTo: `${origin}/auth/oauth?next=/protected`,\n },\n })\n\n if (data.url) {\n return redirect(data.url)\n }\n\n if (error) {\n return {\n error: error instanceof Error ? error.message : 'An error occurred',\n }\n }\n}\n\nexport default function Login() {\n const fetcher = useFetcher<typeof action>()\n\n const error = fetcher.data?.error\n const loading = fetcher.state === 'submitting'\n\n return (\n <div className=\"flex min-h-svh w-full items-center justify-center p-6 md:p-10\">\n <div className=\"w-full max-w-sm\">\n <div className=\"flex flex-col gap-6\">\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Welcome!</CardTitle>\n <CardDescription>Sign in to your account to continue</CardDescription>\n </CardHeader>\n <CardContent>\n <fetcher.Form method=\"post\">\n <div className=\"flex flex-col gap-6\">\n {error && <p className=\"text-sm text-destructive-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={loading}>\n {loading ? 'Logging in...' : 'Continue with GitHub'}\n </Button>\n </div>\n </fetcher.Form>\n </CardContent>\n </Card>\n </div>\n </div>\n </div>\n )\n}\n",+ "content": "import { redirect, useFetcher, useSearchParams, type ActionFunctionArgs } from 'react-router'\n\nimport { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'\nimport { createClient } from '@/registry/default/clients/react-router/lib/supabase/server'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\n\nexport const action = async ({ request }: ActionFunctionArgs) => {\n const { supabase, headers } = createClient(request)\n const origin = new URL(request.url).origin\n\n const formData = await request.formData()\n const next = safeNextPath(formData.get('next'), '/protected', origin)\n\n const { data, error } = await supabase.auth.signInWithOAuth({\n provider: 'github',\n options: {\n redirectTo: `${origin}/auth/oauth?next=${encodeURIComponent(next)}`,\n },\n })\n\n if (data.url) {\n return redirect(data.url, { headers })\n }\n\n if (error) {\n return {\n error: error instanceof Error ? error.message : 'An error occurred',\n }\n }\n}\n\nexport default function Login() {\n const fetcher = useFetcher<typeof action>()\n const [searchParams] = useSearchParams()\n\n const error = fetcher.data?.error\n const loading = fetcher.state === 'submitting'\n\n return (\n <div className=\"flex min-h-svh w-full items-center justify-center p-6 md:p-10\">\n <div className=\"w-full max-w-sm\">\n <div className=\"flex flex-col gap-6\">\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Welcome!</CardTitle>\n <CardDescription>Sign in to your account to continue</CardDescription>\n </CardHeader>\n <CardContent>\n <fetcher.Form method=\"post\">\n <input type=\"hidden\" name=\"next\" value={searchParams.get('next') ?? ''} />\n <div className=\"flex flex-col gap-6\">\n {error && <p className=\"text-sm text-destructive-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={loading}>\n {loading ? 'Logging in...' : 'Continue with GitHub'}\n </Button>\n </div>\n </fetcher.Form>\n </CardContent>\n </Card>\n </div>\n </div>\n </div>\n )\n}\n","type": "registry:file","target": "app/routes/login.tsx"},diff --git a/apps/ui-library/public/r/social-auth-tanstack.json b/apps/ui-library/public/r/social-auth-tanstack.jsonindex 4dddd3c7469..6f5aae7f630 100644--- a/apps/ui-library/public/r/social-auth-tanstack.json+++ b/apps/ui-library/public/r/social-auth-tanstack.json@@ -10,12 +10,13 @@],"registryDependencies": ["button",- "card"+ "card",+ "https://supabase.com/library/r/safe-next-path.json"],"files": [{"path": "registry/default/blocks/social-auth-tanstack/components/login-form.tsx",- "content": "import { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\nimport { createClient } from '@/registry/default/clients/tanstack/lib/supabase/client'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\n\nexport function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<'div'>) {\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n\n const handleSocialLogin = async (e: React.FormEvent) => {\n e.preventDefault()\n const supabase = createClient()\n setIsLoading(true)\n setError(null)\n\n try {\n const { error } = await supabase.auth.signInWithOAuth({\n provider: 'github',\n options: {\n redirectTo: `${window.location.origin}/auth/oauth?next=/protected`,\n },\n })\n\n if (error) throw error\n } catch (error: unknown) {\n setError(error instanceof Error ? error.message : 'An error occurred')\n setIsLoading(false)\n }\n }\n\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Welcome!</CardTitle>\n <CardDescription>Sign in to your account to continue</CardDescription>\n </CardHeader>\n <CardContent>\n <form onSubmit={handleSocialLogin}>\n <div className=\"flex flex-col gap-6\">\n {error && <p className=\"text-sm text-destructive-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={isLoading}>\n {isLoading ? 'Logging in...' : 'Continue with GitHub'}\n </Button>\n </div>\n </form>\n </CardContent>\n </Card>\n </div>\n )\n}\n",+ "content": "import { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\nimport { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'\nimport { createClient } from '@/registry/default/clients/tanstack/lib/supabase/client'\nimport { Button } from '@/registry/default/components/ui/button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/components/ui/card'\n\nexport function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<'div'>) {\n const [error, setError] = useState<string | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n\n const handleSocialLogin = async (e: React.FormEvent) => {\n e.preventDefault()\n const supabase = createClient()\n setIsLoading(true)\n setError(null)\n\n try {\n const next = new URLSearchParams(window.location.search).get('next')\n const { error } = await supabase.auth.signInWithOAuth({\n provider: 'github',\n options: {\n redirectTo: `${window.location.origin}/auth/confirm?next=${encodeURIComponent(safeNextPath(next, '/protected'))}`,\n },\n })\n\n if (error) throw error\n } catch (error: unknown) {\n setError(error instanceof Error ? error.message : 'An error occurred')\n setIsLoading(false)\n }\n }\n\n return (\n <div className={cn('flex flex-col gap-6', className)} {...props}>\n <Card>\n <CardHeader>\n <CardTitle className=\"text-2xl\">Welcome!</CardTitle>\n <CardDescription>Sign in to your account to continue</CardDescription>\n </CardHeader>\n <CardContent>\n <form onSubmit={handleSocialLogin}>\n <div className=\"flex flex-col gap-6\">\n {error && <p className=\"text-sm text-destructive-500\">{error}</p>}\n <Button type=\"submit\" className=\"w-full\" disabled={isLoading}>\n {isLoading ? 'Logging in...' : 'Continue with GitHub'}\n </Button>\n </div>\n </form>\n </CardContent>\n </Card>\n </div>\n )\n}\n","type": "registry:component"},{diff --git a/apps/ui-library/public/r/supabase-client-nextjs.json b/apps/ui-library/public/r/supabase-client-nextjs.jsonindex c7925d9f8d7..5e8fba07ebe 100644--- a/apps/ui-library/public/r/supabase-client-nextjs.json+++ b/apps/ui-library/public/r/supabase-client-nextjs.json@@ -17,7 +17,7 @@},{"path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",- "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n","type": "registry:lib"},{diff --git a/apps/ui-library/public/r/tanstack-db-nextjs.json b/apps/ui-library/public/r/tanstack-db-nextjs.jsonindex aafa10ab5d0..af5db958533 100644--- a/apps/ui-library/public/r/tanstack-db-nextjs.json+++ b/apps/ui-library/public/r/tanstack-db-nextjs.json@@ -26,7 +26,7 @@},{"path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",- "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth') &&\n // the OAuth consent route sends unauthenticated visitors to the login page\n // itself, so that it can preserve the authorization in the `next` parameter\n request.nextUrl.pathname !== '/oauth/consent'\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n","type": "registry:lib"},{diff --git a/apps/ui-library/registry/blocks.ts b/apps/ui-library/registry/blocks.tsindex 4be38f7085a..f1c045df999 100644--- a/apps/ui-library/registry/blocks.ts+++ b/apps/ui-library/registry/blocks.ts@@ -4,6 +4,10 @@ import { clients } from './clients'import currentUserAvatar from './default/blocks/current-user-avatar/registry-item.json' with { type: 'json' }import dropzone from './default/blocks/dropzone/registry-item.json' with { type: 'json' }import infiniteQueryHook from './default/blocks/infinite-query-hook/registry-item.json' with { type: 'json' }+import oauthConsentNextjs from './default/blocks/oauth-consent-nextjs/registry-item.json' with { type: 'json' }+import oauthConsentReactRouter from './default/blocks/oauth-consent-react-router/registry-item.json' with { type: 'json' }+import oauthConsentReact from './default/blocks/oauth-consent-react/registry-item.json' with { type: 'json' }+import oauthConsentTanstack from './default/blocks/oauth-consent-tanstack/registry-item.json' with { type: 'json' }import passwordBasedAuthNextjs from './default/blocks/password-based-auth-nextjs/registry-item.json' with { type: 'json' }import passwordBasedAuthReactRouter from './default/blocks/password-based-auth-react-router/registry-item.json' with { type: 'json' }import passwordBasedAuthReact from './default/blocks/password-based-auth-react/registry-item.json' with { type: 'json' }@@ -13,6 +17,7 @@ import realtimeChat from './default/blocks/realtime-chat/registry-item.json' witimport realtimeCursor from './default/blocks/realtime-cursor/registry-item.json' with { type: 'json' }import realtimeFlow from './default/blocks/realtime-flow/registry-item.json' with { type: 'json' }import realtimeMonaco from './default/blocks/realtime-monaco/registry-item.json' with { type: 'json' }+import safeNextPath from './default/blocks/safe-next-path/registry-item.json' with { type: 'json' }import socialAuthNextjs from './default/blocks/social-auth-nextjs/registry-item.json' with { type: 'json' }import socialAuthReactRouter from './default/blocks/social-auth-react-router/registry-item.json' with { type: 'json' }import socialAuthReact from './default/blocks/social-auth-react/registry-item.json' with { type: 'json' }@@ -32,12 +37,19 @@ const combine = (component: RegistryItem) => {})}+const withClientAndDocs = (component: RegistryItem, client: RegistryItem) => ({+ ...registryItemAppend(component, [client]),+ docs: [component.docs, client.docs].filter(Boolean).join('\n\n'),+})+const nextjsClient = clients.find((client) => client.name === 'supabase-client-nextjs')const reactClient = clients.find((client) => client.name === 'supabase-client-react')const tanstackClient = clients.find((client) => client.name === 'supabase-client-tanstack')const reactRouterClient = clients.find((client) => client.name === 'supabase-client-react-router')export const blocks = [+ safeNextPath as RegistryItem,+registryItemAppend(passwordBasedAuthNextjs as RegistryItem, [nextjsClient!]),registryItemAppend(passwordBasedAuthReact as RegistryItem, [reactClient!]),registryItemAppend(passwordBasedAuthReactRouter as RegistryItem, [reactRouterClient!]),@@ -58,6 +70,11 @@ export const blocks = [// infinite query hook is intentionally not combined with the clients since it depends on clients having database types.infiniteQueryHook as RegistryItem,+ withClientAndDocs(oauthConsentNextjs as RegistryItem, nextjsClient!),+ withClientAndDocs(oauthConsentReact as RegistryItem, reactClient!),+ withClientAndDocs(oauthConsentReactRouter as RegistryItem, reactRouterClient!),+ withClientAndDocs(oauthConsentTanstack as RegistryItem, tanstackClient!),+// tanstack-db is served dynamically via API route, but we register it here for the static buildregistryItemAppend(tanstackDbNextjs as RegistryItem, [nextjsClient!]),] as RegistryItem[]diff --git a/apps/ui-library/registry/default/blocks/oauth-consent-nextjs/app/oauth/consent/page.tsx b/apps/ui-library/registry/default/blocks/oauth-consent-nextjs/app/oauth/consent/page.tsxnew file mode 100644index 00000000000..444f8b75d80--- /dev/null+++ b/apps/ui-library/registry/default/blocks/oauth-consent-nextjs/app/oauth/consent/page.tsx@@ -0,0 +1,15 @@+import { OAuthConsent } from '@/registry/default/blocks/oauth-consent/components/oauth-consent'++export default async function ConsentPage({+ searchParams,+}: {+ searchParams: Promise<{ authorization_id?: string }>+}) {+ const { authorization_id } = await searchParams++ return (+ <main className="flex min-h-svh items-center justify-center p-6 md:p-10">+ <OAuthConsent className="w-full max-w-lg" authorizationId={authorization_id} />+ </main>+ )+}diff --git a/apps/ui-library/registry/default/blocks/oauth-consent-nextjs/registry-item.json b/apps/ui-library/registry/default/blocks/oauth-consent-nextjs/registry-item.jsonnew file mode 100644index 00000000000..9eb440eed24--- /dev/null+++ b/apps/ui-library/registry/default/blocks/oauth-consent-nextjs/registry-item.json@@ -0,0 +1,23 @@+{+ "name": "oauth-consent-nextjs",+ "type": "registry:block",+ "title": "OAuth Consent for Next.js",+ "description": "OAuth 2.1 consent screen and route for an existing authenticated application.",+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` \u2014 edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```",+ "registryDependencies": ["button", "card", "https://supabase.com/library/r/safe-next-path.json"],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "type": "registry:hook"+ },+ {+ "path": "registry/default/blocks/oauth-consent-nextjs/app/oauth/consent/page.tsx",+ "type": "registry:page",+ "target": "app/oauth/consent/page.tsx"+ }+ ]+}diff --git a/apps/ui-library/registry/default/blocks/oauth-consent-react-router/app/routes/oauth.consent.tsx b/apps/ui-library/registry/default/blocks/oauth-consent-react-router/app/routes/oauth.consent.tsxnew file mode 100644index 00000000000..444a8f4a177--- /dev/null+++ b/apps/ui-library/registry/default/blocks/oauth-consent-react-router/app/routes/oauth.consent.tsx@@ -0,0 +1,16 @@+import { useSearchParams } from 'react-router'++import { OAuthConsent } from '@/registry/default/blocks/oauth-consent/components/oauth-consent'++export default function ConsentRoute() {+ const [searchParams] = useSearchParams()++ return (+ <main className="flex min-h-svh items-center justify-center p-6 md:p-10">+ <OAuthConsent+ className="w-full max-w-lg"+ authorizationId={searchParams.get('authorization_id')}+ />+ </main>+ )+}diff --git a/apps/ui-library/registry/default/blocks/oauth-consent-react-router/registry-item.json b/apps/ui-library/registry/default/blocks/oauth-consent-react-router/registry-item.jsonnew file mode 100644index 00000000000..aafde110873--- /dev/null+++ b/apps/ui-library/registry/default/blocks/oauth-consent-react-router/registry-item.json@@ -0,0 +1,23 @@+{+ "name": "oauth-consent-react-router",+ "type": "registry:block",+ "title": "OAuth Consent for React Router",+ "description": "OAuth 2.1 consent screen and route for an existing authenticated application.",+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` \u2014 edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```",+ "registryDependencies": ["button", "card", "https://supabase.com/library/r/safe-next-path.json"],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "type": "registry:hook"+ },+ {+ "path": "registry/default/blocks/oauth-consent-react-router/app/routes/oauth.consent.tsx",+ "type": "registry:file",+ "target": "app/routes/oauth.consent.tsx"+ }+ ]+}diff --git a/apps/ui-library/registry/default/blocks/oauth-consent-react/registry-item.json b/apps/ui-library/registry/default/blocks/oauth-consent-react/registry-item.jsonnew file mode 100644index 00000000000..40c3f2cd74e--- /dev/null+++ b/apps/ui-library/registry/default/blocks/oauth-consent-react/registry-item.json@@ -0,0 +1,18 @@+{+ "name": "oauth-consent-react",+ "type": "registry:block",+ "title": "OAuth Consent for React",+ "description": "OAuth 2.1 consent component for an existing authenticated application.",+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` \u2014 edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```",+ "registryDependencies": ["button", "card", "https://supabase.com/library/r/safe-next-path.json"],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "type": "registry:hook"+ }+ ]+}diff --git a/apps/ui-library/registry/default/blocks/oauth-consent-tanstack/registry-item.json b/apps/ui-library/registry/default/blocks/oauth-consent-tanstack/registry-item.jsonnew file mode 100644index 00000000000..f531763b62b--- /dev/null+++ b/apps/ui-library/registry/default/blocks/oauth-consent-tanstack/registry-item.json@@ -0,0 +1,23 @@+{+ "name": "oauth-consent-tanstack",+ "type": "registry:block",+ "title": "OAuth Consent for TanStack Start",+ "description": "OAuth 2.1 consent screen and route for an existing authenticated application.",+ "docs": "After installation, set the following in `supabase/config.toml`. Recent CLI versions already write an `[auth.oauth_server]` section with `enabled = false` \u2014 edit that section rather than adding a second one:\n\n```toml\n[auth.oauth_server]\nenabled = true\nauthorization_url_path = \"/oauth/consent\"\n```",+ "registryDependencies": ["button", "card", "https://supabase.com/library/r/safe-next-path.json"],+ "files": [+ {+ "path": "registry/default/blocks/oauth-consent/components/oauth-consent.tsx",+ "type": "registry:component"+ },+ {+ "path": "registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts",+ "type": "registry:hook"+ },+ {+ "path": "registry/default/blocks/oauth-consent-tanstack/routes/oauth/consent.tsx",+ "type": "registry:file",+ "target": "routes/oauth/consent.tsx"+ }+ ]+}diff --git a/apps/ui-library/registry/default/blocks/oauth-consent-tanstack/routes/oauth/consent.tsx b/apps/ui-library/registry/default/blocks/oauth-consent-tanstack/routes/oauth/consent.tsxnew file mode 100644index 00000000000..ba795f23955--- /dev/null+++ b/apps/ui-library/registry/default/blocks/oauth-consent-tanstack/routes/oauth/consent.tsx@@ -0,0 +1,23 @@+import { createFileRoute } from '@tanstack/react-router'++import { OAuthConsent } from '@/registry/default/blocks/oauth-consent/components/oauth-consent'++// This route is installed into the consumer's routes directory. Their TanStack+// route generator adds it to FileRoutesByPath after installation.+// @ts-expect-error The local generated route tree does not include this block route.+export const Route = createFileRoute('/oauth/consent')({+ component: ConsentPage,+ validateSearch: (search) => ({+ authorization_id: typeof search.authorization_id === 'string' ? search.authorization_id : null,+ }),+})++function ConsentPage() {+ const { authorization_id } = Route.useSearch()++ return (+ <main className="flex min-h-svh items-center justify-center p-6 md:p-10">+ <OAuthConsent className="w-full max-w-lg" authorizationId={authorization_id} />+ </main>+ )+}diff --git a/apps/ui-library/registry/default/blocks/oauth-consent/components/oauth-consent.tsx b/apps/ui-library/registry/default/blocks/oauth-consent/components/oauth-consent.tsxnew file mode 100644index 00000000000..c143f515c77--- /dev/null+++ b/apps/ui-library/registry/default/blocks/oauth-consent/components/oauth-consent.tsx@@ -0,0 +1,173 @@+'use client'++import { cn } from '@/lib/utils'+import {+ useOAuthConsent,+ type OAuthConsentDecision,+} from '@/registry/default/blocks/oauth-consent/hooks/use-oauth-consent'+import { Button } from '@/registry/default/components/ui/button'+import {+ Card,+ CardContent,+ CardDescription,+ CardHeader,+ CardTitle,+} from '@/registry/default/components/ui/card'++const getInitial = (value: string) => value.trim().charAt(0).toUpperCase() || '?'++interface ConsentCardShellProps extends React.ComponentPropsWithoutRef<'div'> {+ clientName: string+ productName: string+}++function ConsentCardShell({+ clientName,+ productName,+ className,+ children,+ ...props+}: ConsentCardShellProps) {+ return (+ <div className={cn('flex flex-col gap-6', className)} {...props}>+ <Card>+ <CardHeader className="items-center space-y-4 text-center">+ <div+ className="flex items-center justify-center"+ aria-label={`${clientName} connecting to ${productName}`}+ >+ <div className="flex size-12 items-center justify-center rounded-full border bg-muted font-medium">+ {getInitial(clientName)}+ </div>+ <div className="h-px w-8 bg-border" aria-hidden="true" />+ <div className="flex size-12 items-center justify-center rounded-full border bg-muted font-medium">+ {getInitial(productName)}+ </div>+ </div>+ <div className="space-y-1.5">+ <CardTitle className="text-2xl">Authorize {clientName}</CardTitle>+ <CardDescription>Review what this client gets access to.</CardDescription>+ </div>+ </CardHeader>+ <CardContent className="space-y-6">{children}</CardContent>+ </Card>+ </div>+ )+}++export interface OAuthConsentCardProps extends React.ComponentPropsWithoutRef<'div'> {+ clientName: string+ productName?: string+ redirectUri: string+ email: string+ scopes?: string[]+ error?: string | null+ decision?: OAuthConsentDecision | null+ onApprove?: () => void+ onDeny?: () => void+}++export function OAuthConsentCard({+ clientName,+ productName = 'Your product',+ redirectUri,+ email,+ scopes = [],+ error = null,+ decision = null,+ onApprove,+ onDeny,+ ...props+}: OAuthConsentCardProps) {+ return (+ <ConsentCardShell clientName={clientName} productName={productName} {...props}>+ <dl className="divide-y rounded-lg border text-sm">+ <div className="flex items-center justify-between gap-6 p-4">+ <dt className="text-muted-foreground">Client</dt>+ <dd className="min-w-0 break-all text-right font-medium">{clientName}</dd>+ </div>+ <div className="flex items-center justify-between gap-6 p-4">+ <dt className="text-muted-foreground">Redirects to</dt>+ <dd className="min-w-0 break-all text-right font-medium">{redirectUri}</dd>+ </div>+ <div className="flex items-center justify-between gap-6 p-4">+ <dt className="text-muted-foreground">Signed in as</dt>+ <dd className="min-w-0 break-all text-right font-medium">{email}</dd>+ </div>+ {scopes.length > 0 && (+ <div className="flex items-center justify-between gap-6 p-4">+ <dt className="text-muted-foreground">Scopes</dt>+ <dd className="min-w-0 break-all text-right font-medium">{scopes.join(', ')}</dd>+ </div>+ )}+ </dl>+ <p className="text-sm text-muted-foreground">+ Allow access only if you recognize this application. It can act on your behalf only within+ the requested permissions and the access you already have.+ </p>+ {error && (+ <p role="alert" className="text-sm text-destructive">+ {error}+ </p>+ )}+ <div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">+ <Button type="button" variant="outline" disabled={decision !== null} onClick={onDeny}>+ {decision === 'deny' ? 'Denying...' : 'Deny'}+ </Button>+ <Button type="button" disabled={decision !== null} onClick={onApprove}>+ {decision === 'approve' ? 'Allowing...' : 'Allow access'}+ </Button>+ </div>+ </ConsentCardShell>+ )+}++interface OAuthConsentProps extends React.ComponentPropsWithoutRef<'div'> {+ authorizationId?: string | null+ signInPath?: string+ productName?: string+}++export function OAuthConsent({+ authorizationId,+ signInPath = '/auth/login',+ productName = 'Your product',+ ...props+}: OAuthConsentProps) {+ const { details, email, error, isLoading, decision, approve, deny } = useOAuthConsent({+ authorizationId,+ signInPath,+ })++ if (isLoading || !details || !email) {+ return (+ <ConsentCardShell clientName="OAuth client" productName={productName} {...props}>+ {isLoading ? (+ <p role="status" className="text-sm text-muted-foreground">+ Loading authorization request...+ </p>+ ) : (+ <p role="alert" className="text-sm text-destructive">+ {error ??+ 'Unable to load the authorization request. Start again from your OAuth client.'}+ </p>+ )}+ </ConsentCardShell>+ )+ }++ return (+ <OAuthConsentCard+ clientName={details.client.name}+ productName={productName}+ redirectUri={details.redirect_uri}+ email={email}+ scopes={details.scope.split(' ').filter(Boolean)}+ error={error}+ decision={decision}+ onApprove={() => void approve()}+ onDeny={() => void deny()}+ {...props}+ />+ )+}diff --git a/apps/ui-library/registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts b/apps/ui-library/registry/default/blocks/oauth-consent/hooks/use-oauth-consent.tsnew file mode 100644index 00000000000..337381b6c74--- /dev/null+++ b/apps/ui-library/registry/default/blocks/oauth-consent/hooks/use-oauth-consent.ts@@ -0,0 +1,147 @@+import { isAuthSessionMissingError } from '@supabase/supabase-js'+import type { OAuthAuthorizationDetails } from '@supabase/supabase-js'+import { useCallback, useEffect, useRef, useState } from 'react'++import { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'+import { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'++export type OAuthConsentDecision = 'approve' | 'deny'++export interface UseOAuthConsentOptions {+ authorizationId?: string | null+ signInPath?: string+}++const withNextParam = (path: string, next: string) => {+ const url = new URL(path, window.location.origin)+ const searchParams = new URLSearchParams(url.search)+ searchParams.set('next', next)+ url.search = searchParams.toString()+ return `${url.pathname}${url.search}${url.hash}`+}++const useOAuthConsent = ({+ authorizationId,+ signInPath = '/auth/login',+}: UseOAuthConsentOptions) => {+ const [details, setDetails] = useState<OAuthAuthorizationDetails | null>(null)+ const [error, setError] = useState<string | null>(null)+ const [isLoading, setIsLoading] = useState(true)+ const [decision, setDecision] = useState<OAuthConsentDecision | null>(null)+ const isDeciding = useRef(false)++ useEffect(() => {+ let active = true++ const loadAuthorization = async () => {+ setIsLoading(true)+ setError(null)+ setDetails(null)+ setDecision(null)++ if (!authorizationId) {+ setError('This page needs an authorization_id. Start again from your OAuth client.')+ setIsLoading(false)+ return+ }++ const supabase = createClient()+ const {+ data: { user },+ error: userError,+ } = await supabase.auth.getUser()++ if (userError && !isAuthSessionMissingError(userError)) {+ if (active) {+ setError(userError.message)+ setIsLoading(false)+ }+ return+ }++ if (!user) {+ const next = `${window.location.pathname}${window.location.search}`+ if (active) {+ window.location.replace(withNextParam(safeNextPath(signInPath, '/auth/login'), next))+ }+ return+ }++ const { data, error } = await supabase.auth.oauth.getAuthorizationDetails(authorizationId)+ if (error) {+ if (active) {+ setError(error.message)+ setIsLoading(false)+ }+ return+ }++ if (!('authorization_id' in data)) {+ if (active) {+ window.location.replace(data.redirect_url)+ }+ return+ }++ if (active) {+ setDetails(data)+ setIsLoading(false)+ }+ }++ void loadAuthorization()+ return () => {+ active = false+ }+ }, [authorizationId, signInPath])++ const decide = useCallback(+ async (action: OAuthConsentDecision) => {+ if (!authorizationId || isDeciding.current) return++ isDeciding.current = true+ setDecision(action)+ setError(null)+ const supabase = createClient()+ const result =+ action === 'approve'+ ? await supabase.auth.oauth.approveAuthorization(authorizationId, {+ skipBrowserRedirect: true,+ })+ : await supabase.auth.oauth.denyAuthorization(authorizationId, {+ skipBrowserRedirect: true,+ })++ if (result.error) {+ setError(result.error.message)+ setDecision(null)+ isDeciding.current = false+ return+ }++ if (!result.data?.redirect_url) {+ setError('The server did not return a redirect. Start again from your OAuth client.')+ setDecision(null)+ isDeciding.current = false+ return+ }++ window.location.assign(result.data.redirect_url)+ },+ [authorizationId]+ )++ return {+ details,+ email: details?.user.email ?? null,+ error,+ isLoading,+ decision,+ approve: () => decide('approve'),+ deny: () => decide('deny'),+ }+}++type UseOAuthConsentReturn = ReturnType<typeof useOAuthConsent>++export { useOAuthConsent, type OAuthAuthorizationDetails, type UseOAuthConsentReturn }diff --git a/apps/ui-library/registry/default/blocks/password-based-auth-nextjs/components/login-form.tsx b/apps/ui-library/registry/default/blocks/password-based-auth-nextjs/components/login-form.tsxindex 30dc1967093..39bc9640d7b 100644--- a/apps/ui-library/registry/default/blocks/password-based-auth-nextjs/components/login-form.tsx+++ b/apps/ui-library/registry/default/blocks/password-based-auth-nextjs/components/login-form.tsx@@ -4,6 +4,7 @@ import { useRouter } from 'next/navigation'import { useState } from 'react'import { cn } from '@/lib/utils'+import { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'import { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'import { Button } from '@/registry/default/components/ui/button'import {@@ -37,7 +38,8 @@ export function LoginForm({ className, ...props }: React.ComponentPropsWithoutRe})if (error) throw error// Update this route to redirect to an authenticated route. The user already has an active session.- router.push('/example/password-based-auth/protected')+ const next = new URLSearchParams(window.location.search).get('next')+ router.push(safeNextPath(next, '/example/password-based-auth/protected'))} catch (error: unknown) {setError(error instanceof Error ? error.message : 'An error occurred')} finally {diff --git a/apps/ui-library/registry/default/blocks/password-based-auth-nextjs/registry-item.json b/apps/ui-library/registry/default/blocks/password-based-auth-nextjs/registry-item.jsonindex 2203774c8dc..f0a593ff84f 100644--- a/apps/ui-library/registry/default/blocks/password-based-auth-nextjs/registry-item.json+++ b/apps/ui-library/registry/default/blocks/password-based-auth-nextjs/registry-item.json@@ -3,7 +3,13 @@"type": "registry:block","title": "Password Based Auth flow for Nextjs and Supabase","description": "Password Based Auth flow for Nextjs and Supabase",- "registryDependencies": ["button", "card", "input", "label"],+ "registryDependencies": [+ "button",+ "card",+ "input",+ "label",+ "https://supabase.com/library/r/safe-next-path.json"+ ],"dependencies": ["@supabase/ssr@latest", "@supabase/supabase-js@latest"],"files": [{diff --git a/apps/ui-library/registry/default/blocks/password-based-auth-react-router/app/routes/login.tsx b/apps/ui-library/registry/default/blocks/password-based-auth-react-router/app/routes/login.tsxindex 04ff0dc4286..15d9defc342 100644--- a/apps/ui-library/registry/default/blocks/password-based-auth-react-router/app/routes/login.tsx+++ b/apps/ui-library/registry/default/blocks/password-based-auth-react-router/app/routes/login.tsx@@ -1,5 +1,6 @@-import { Link, redirect, useFetcher, type ActionFunctionArgs } from 'react-router'+import { Link, redirect, useFetcher, useSearchParams, type ActionFunctionArgs } from 'react-router'+import { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'import { createClient } from '@/registry/default/clients/react-router/lib/supabase/server'import { Button } from '@/registry/default/components/ui/button'import {@@ -14,6 +15,7 @@ import { Label } from '@/registry/default/components/ui/label'export const action = async ({ request }: ActionFunctionArgs) => {const { supabase, headers } = createClient(request)+ const origin = new URL(request.url).originconst formData = await request.formData()@@ -32,11 +34,12 @@ export const action = async ({ request }: ActionFunctionArgs) => {}// Update this route to redirect to an authenticated route. The user already has an active session.- return redirect('/protected', { headers })+ return redirect(safeNextPath(formData.get('next'), '/protected', origin), { headers })}export default function Login() {const fetcher = useFetcher<typeof action>()+ const [searchParams] = useSearchParams()const error = fetcher.data?.errorconst loading = fetcher.state === 'submitting'@@ -52,6 +55,7 @@ export default function Login() {</CardHeader><CardContent><fetcher.Form method="post">+ <input type="hidden" name="next" value={searchParams.get('next') ?? ''} /><div className="flex flex-col gap-6"><div className="grid gap-2"><Label htmlFor="email">Email</Label>diff --git a/apps/ui-library/registry/default/blocks/password-based-auth-react-router/registry-item.json b/apps/ui-library/registry/default/blocks/password-based-auth-react-router/registry-item.jsonindex be88ea48904..b0ac01f4c0d 100644--- a/apps/ui-library/registry/default/blocks/password-based-auth-react-router/registry-item.json+++ b/apps/ui-library/registry/default/blocks/password-based-auth-react-router/registry-item.json@@ -3,7 +3,13 @@"type": "registry:block","title": "Password Based Auth flow for React Router and Supabase","description": "Password Based Auth flow for React Router and Supabase",- "registryDependencies": ["button", "card", "input", "label"],+ "registryDependencies": [+ "button",+ "card",+ "input",+ "label",+ "https://supabase.com/library/r/safe-next-path.json"+ ],"dependencies": ["@supabase/ssr@latest","@react-router/dev@latest",diff --git a/apps/ui-library/registry/default/blocks/password-based-auth-react/components/login-form.tsx b/apps/ui-library/registry/default/blocks/password-based-auth-react/components/login-form.tsxindex 89575682af2..9b0c71b95cf 100644--- a/apps/ui-library/registry/default/blocks/password-based-auth-react/components/login-form.tsx+++ b/apps/ui-library/registry/default/blocks/password-based-auth-react/components/login-form.tsx@@ -1,6 +1,7 @@import { useState } from 'react'import { cn } from '@/lib/utils'+import { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'import { createClient } from '@/registry/default/clients/react/lib/supabase/client'import { Button } from '@/registry/default/components/ui/button'import {@@ -32,7 +33,8 @@ export function LoginForm({ className, ...props }: React.ComponentPropsWithoutRe})if (error) throw error// Update this route to redirect to an authenticated route. The user already has an active session.- location.href = '/protected'+ const next = new URLSearchParams(window.location.search).get('next')+ location.href = safeNextPath(next, '/protected')} catch (error: unknown) {setError(error instanceof Error ? error.message : 'An error occurred')} finally {diff --git a/apps/ui-library/registry/default/blocks/password-based-auth-react/registry-item.json b/apps/ui-library/registry/default/blocks/password-based-auth-react/registry-item.jsonindex 459510f698e..73b2bb342a8 100644--- a/apps/ui-library/registry/default/blocks/password-based-auth-react/registry-item.json+++ b/apps/ui-library/registry/default/blocks/password-based-auth-react/registry-item.json@@ -3,7 +3,13 @@"type": "registry:block","title": "Password Based Auth flow for React and Supabase","description": "Password Based Auth flow for React and Supabase",- "registryDependencies": ["button", "card", "input", "label"],+ "registryDependencies": [+ "button",+ "card",+ "input",+ "label",+ "https://supabase.com/library/r/safe-next-path.json"+ ],"files": [{"path": "registry/default/blocks/password-based-auth-react/components/login-form.tsx",diff --git a/apps/ui-library/registry/default/blocks/password-based-auth-tanstack/components/login-form.tsx b/apps/ui-library/registry/default/blocks/password-based-auth-tanstack/components/login-form.tsxindex cfb46c7b53e..00824c9fad8 100644--- a/apps/ui-library/registry/default/blocks/password-based-auth-tanstack/components/login-form.tsx+++ b/apps/ui-library/registry/default/blocks/password-based-auth-tanstack/components/login-form.tsx@@ -1,7 +1,8 @@-import { Link, useNavigate } from '@tanstack/react-router'+import { Link } from '@tanstack/react-router'import { useState } from 'react'import { cn } from '@/lib/utils'+import { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'import { createClient } from '@/registry/default/clients/tanstack/lib/supabase/client'import { Button } from '@/registry/default/components/ui/button'import {@@ -19,7 +20,6 @@ export function LoginForm({ className, ...props }: React.ComponentPropsWithoutReconst [password, setPassword] = useState('')const [error, setError] = useState<string | null>(null)const [isLoading, setIsLoading] = useState(false)- const navigate = useNavigate()const handleLogin = async (e: React.FormEvent) => {e.preventDefault()@@ -33,8 +33,11 @@ export function LoginForm({ className, ...props }: React.ComponentPropsWithoutRepassword,})if (error) throw error- // Update this route to redirect to an authenticated route. The user already has an active session.- await navigate({ to: '/protected' })+ // Follow the `next` query parameter if it is a same-origin relative path, e.g. when+ // the OAuth consent screen sent the user here to sign in first. It may point outside+ // the typed route tree, so it needs a full navigation.+ const next = new URLSearchParams(window.location.search).get('next')+ window.location.assign(safeNextPath(next, '/protected'))} catch (error: unknown) {setError(error instanceof Error ? error.message : 'An error occurred')} finally {diff --git a/apps/ui-library/registry/default/blocks/password-based-auth-tanstack/registry-item.json b/apps/ui-library/registry/default/blocks/password-based-auth-tanstack/registry-item.jsonindex eb78910ed8a..43f4673a848 100644--- a/apps/ui-library/registry/default/blocks/password-based-auth-tanstack/registry-item.json+++ b/apps/ui-library/registry/default/blocks/password-based-auth-tanstack/registry-item.json@@ -3,7 +3,13 @@"type": "registry:block","title": "Password Based Auth flow for tanstack and Supabase","description": "Password Based Auth flow for tanstack and Supabase",- "registryDependencies": ["button", "card", "input", "label"],+ "registryDependencies": [+ "button",+ "card",+ "input",+ "label",+ "https://supabase.com/library/r/safe-next-path.json"+ ],"dependencies": ["@supabase/ssr@latest"],"files": [{diff --git a/apps/ui-library/registry/default/blocks/safe-next-path/lib/safe-next-path.ts b/apps/ui-library/registry/default/blocks/safe-next-path/lib/safe-next-path.tsnew file mode 100644index 00000000000..f727da65643--- /dev/null+++ b/apps/ui-library/registry/default/blocks/safe-next-path/lib/safe-next-path.ts@@ -0,0 +1,12 @@+export const safeNextPath = (path: unknown, fallback = '/', origin?: string) => {+ if (typeof path !== 'string' || !path.startsWith('/')) return fallback++ const currentOrigin = origin ?? window.location.origin++ try {+ const url = new URL(path, currentOrigin)+ return url.origin === currentOrigin ? `${url.pathname}${url.search}${url.hash}` : fallback+ } catch {+ return fallback+ }+}diff --git a/apps/ui-library/registry/default/blocks/safe-next-path/registry-item.json b/apps/ui-library/registry/default/blocks/safe-next-path/registry-item.jsonnew file mode 100644index 00000000000..130e136101e--- /dev/null+++ b/apps/ui-library/registry/default/blocks/safe-next-path/registry-item.json@@ -0,0 +1,16 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "safe-next-path",+ "type": "registry:lib",+ "title": "Safe next path",+ "description": "Validates same-origin paths before redirecting.",+ "registryDependencies": [],+ "dependencies": [],+ "files": [+ {+ "path": "registry/default/blocks/safe-next-path/lib/safe-next-path.ts",+ "type": "registry:lib",+ "target": "lib/safe-next-path.ts"+ }+ ]+}diff --git a/apps/ui-library/registry/default/blocks/social-auth-nextjs/components/login-form.tsx b/apps/ui-library/registry/default/blocks/social-auth-nextjs/components/login-form.tsxindex 9b12133009f..fb8c80893c2 100644--- a/apps/ui-library/registry/default/blocks/social-auth-nextjs/components/login-form.tsx+++ b/apps/ui-library/registry/default/blocks/social-auth-nextjs/components/login-form.tsx@@ -3,6 +3,7 @@import { useState } from 'react'import { cn } from '@/lib/utils'+import { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'import { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'import { Button } from '@/registry/default/components/ui/button'import {@@ -24,10 +25,11 @@ export function LoginForm({ className, ...props }: React.ComponentPropsWithoutResetError(null)try {+ const next = new URLSearchParams(window.location.search).get('next')const { error } = await supabase.auth.signInWithOAuth({provider: 'github',options: {- redirectTo: `${window.location.origin}/auth/oauth?next=/protected`,+ redirectTo: `${window.location.origin}/auth/oauth?next=${encodeURIComponent(safeNextPath(next, '/protected'))}`,},})diff --git a/apps/ui-library/registry/default/blocks/social-auth-nextjs/registry-item.json b/apps/ui-library/registry/default/blocks/social-auth-nextjs/registry-item.jsonindex c37a59023ea..d3b16a1fdc2 100644--- a/apps/ui-library/registry/default/blocks/social-auth-nextjs/registry-item.json+++ b/apps/ui-library/registry/default/blocks/social-auth-nextjs/registry-item.json@@ -3,7 +3,7 @@"type": "registry:block","title": "Social Auth flow for Nextjs and Supabase","description": "Social Auth flow for Nextjs and Supabase",- "registryDependencies": ["button", "card"],+ "registryDependencies": ["button", "card", "https://supabase.com/library/r/safe-next-path.json"],"dependencies": ["@supabase/ssr@latest", "@supabase/supabase-js@latest"],"files": [{diff --git a/apps/ui-library/registry/default/blocks/social-auth-react-router/app/routes/login.tsx b/apps/ui-library/registry/default/blocks/social-auth-react-router/app/routes/login.tsxindex 9ad26a0bb4a..70ff49bc99c 100644--- a/apps/ui-library/registry/default/blocks/social-auth-react-router/app/routes/login.tsx+++ b/apps/ui-library/registry/default/blocks/social-auth-react-router/app/routes/login.tsx@@ -1,5 +1,6 @@-import { redirect, useFetcher, type ActionFunctionArgs } from 'react-router'+import { redirect, useFetcher, useSearchParams, type ActionFunctionArgs } from 'react-router'+import { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'import { createClient } from '@/registry/default/clients/react-router/lib/supabase/server'import { Button } from '@/registry/default/components/ui/button'import {@@ -11,18 +12,21 @@ import {} from '@/registry/default/components/ui/card'export const action = async ({ request }: ActionFunctionArgs) => {- const { supabase } = createClient(request)+ const { supabase, headers } = createClient(request)const origin = new URL(request.url).origin+ const formData = await request.formData()+ const next = safeNextPath(formData.get('next'), '/protected', origin)+const { data, error } = await supabase.auth.signInWithOAuth({provider: 'github',options: {- redirectTo: `${origin}/auth/oauth?next=/protected`,+ redirectTo: `${origin}/auth/oauth?next=${encodeURIComponent(next)}`,},})if (data.url) {- return redirect(data.url)+ return redirect(data.url, { headers })}if (error) {@@ -34,6 +38,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {export default function Login() {const fetcher = useFetcher<typeof action>()+ const [searchParams] = useSearchParams()const error = fetcher.data?.errorconst loading = fetcher.state === 'submitting'@@ -49,6 +54,7 @@ export default function Login() {</CardHeader><CardContent><fetcher.Form method="post">+ <input type="hidden" name="next" value={searchParams.get('next') ?? ''} /><div className="flex flex-col gap-6">{error && <p className="text-sm text-destructive-500">{error}</p>}<Button type="submit" className="w-full" disabled={loading}>diff --git a/apps/ui-library/registry/default/blocks/social-auth-react-router/registry-item.json b/apps/ui-library/registry/default/blocks/social-auth-react-router/registry-item.jsonindex 6a83ad46e74..656ed9beb9e 100644--- a/apps/ui-library/registry/default/blocks/social-auth-react-router/registry-item.json+++ b/apps/ui-library/registry/default/blocks/social-auth-react-router/registry-item.json@@ -3,7 +3,7 @@"type": "registry:block","title": "Social Auth flow for React Router and Supabase","description": "Social Auth flow for React Router and Supabase",- "registryDependencies": ["button", "card"],+ "registryDependencies": ["button", "card", "https://supabase.com/library/r/safe-next-path.json"],"dependencies": ["@supabase/ssr@latest","@react-router/dev@latest",diff --git a/apps/ui-library/registry/default/blocks/social-auth-tanstack/components/login-form.tsx b/apps/ui-library/registry/default/blocks/social-auth-tanstack/components/login-form.tsxindex 6dceffd6acc..8f16711a82f 100644--- a/apps/ui-library/registry/default/blocks/social-auth-tanstack/components/login-form.tsx+++ b/apps/ui-library/registry/default/blocks/social-auth-tanstack/components/login-form.tsx@@ -1,6 +1,7 @@import { useState } from 'react'import { cn } from '@/lib/utils'+import { safeNextPath } from '@/registry/default/blocks/safe-next-path/lib/safe-next-path'import { createClient } from '@/registry/default/clients/tanstack/lib/supabase/client'import { Button } from '@/registry/default/components/ui/button'import {@@ -22,10 +23,11 @@ export function LoginForm({ className, ...props }: React.ComponentPropsWithoutResetError(null)try {+ const next = new URLSearchParams(window.location.search).get('next')const { error } = await supabase.auth.signInWithOAuth({provider: 'github',options: {- redirectTo: `${window.location.origin}/auth/oauth?next=/protected`,+ redirectTo: `${window.location.origin}/auth/confirm?next=${encodeURIComponent(safeNextPath(next, '/protected'))}`,},})diff --git a/apps/ui-library/registry/default/blocks/social-auth-tanstack/registry-item.json b/apps/ui-library/registry/default/blocks/social-auth-tanstack/registry-item.jsonindex 4fe31a9572b..d93aa8af752 100644--- a/apps/ui-library/registry/default/blocks/social-auth-tanstack/registry-item.json+++ b/apps/ui-library/registry/default/blocks/social-auth-tanstack/registry-item.json@@ -3,7 +3,7 @@"type": "registry:block","title": "Social Auth flow for TanStack and Supabase","description": "Social Auth flow for TanStack and Supabase",- "registryDependencies": ["button", "card"],+ "registryDependencies": ["button", "card", "https://supabase.com/library/r/safe-next-path.json"],"dependencies": ["@supabase/ssr@latest"],"files": [{diff --git a/apps/ui-library/registry/default/clients/nextjs/lib/supabase/middleware.ts b/apps/ui-library/registry/default/clients/nextjs/lib/supabase/middleware.tsindex a022ea53f68..a57b583d66e 100644--- a/apps/ui-library/registry/default/clients/nextjs/lib/supabase/middleware.ts+++ b/apps/ui-library/registry/default/clients/nextjs/lib/supabase/middleware.ts@@ -41,7 +41,10 @@ export async function updateSession(request: NextRequest) {if (!user &&!request.nextUrl.pathname.startsWith('/login') &&- !request.nextUrl.pathname.startsWith('/auth')+ !request.nextUrl.pathname.startsWith('/auth') &&+ // the OAuth consent route sends unauthenticated visitors to the login page+ // itself, so that it can preserve the authorization in the `next` parameter+ request.nextUrl.pathname !== '/oauth/consent') {// no user, potentially respond by redirecting the user to the login pageconst url = request.nextUrl.clone()