mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
docs/reference-template
9
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
ccabb68033 |
fix(docs,examples): keep auth callback redirects within the app (#54500)
## Problem Several auth callback and email confirmation examples redirect to the `next` query parameter without checking it. A reader who copies one gets an open redirect: anyone can send a sign-in link with `next` set to another site, and the app sends the signed-in user there. The affected examples are the SvelteKit, Astro, Remix, and Express tabs of the PKCE flow partial, which all social sign-in pages include, and the Next.js, Astro, Remix, and Express email confirmation handlers in the password guide. The SvelteKit and Express tabs had a partial check, but `//evil.com` and `/\evil.com` still got through. The SvelteKit confirmation tabs and the Next.js reset tab in the password guide copy `next` into the URL path. That keeps the user on the same site, but turns a full URL into a broken path. The example apps under `examples/` have the same problem. The Next.js email confirmation route in `examples/auth/nextjs-full` has the same open redirect. Two SvelteKit example apps copy `next` into the URL path, which keeps the user on the same site but turns a full URL into a broken path. Resolves [DOCS-1836](https://linear.app/supabase/issue/DOCS-1836/make-the-auth-callback-examples-redirect-only-within-the-app), [DOCS-1840](https://linear.app/supabase/issue/DOCS-1840/make-the-auth-examples-under-examples-redirect-only-within-the-app), and [DOCS-1844](https://linear.app/supabase/issue/DOCS-1844/handle-full-url-and-query-string-next-values-in-the-confirmation). ## Solution Each example now reads `next` as a URL against the request's own origin. It keeps `next` only when the result uses `http` or `https`, has the request's host, and its path doesn't start with `//`, then redirects to that path. Anything else falls back to `/`. The examples accept same-site full URLs as well as paths. The signup email template on the password page sends `next={{ .RedirectTo }}`, which is always a full URL, so a path-only check would send every new user to `/`. #51567 proposed a path-only check for the same examples, and this PR builds on it with full-URL support. The redirect itself stays relative. An absolute URL built from the request origin can point to an internal host when the app runs behind a proxy. `URL.parse()` returns `null` for malformed input, so a bad `next` value or `Host` header falls back to `/` instead of throwing. Each check compares the host of `next` with the request's host. Behind a proxy that terminates HTTPS, Express reports the request as `http`, so comparing full origins would send every full-URL `next` to `/`. The redirect carries only the path, so the scheme doesn't affect where the user lands. Other schemes are rejected, because a URL such as `custom://example.com/\evil.com` keeps the backslash in its path, and browsers read `/\evil.com` as another site. The Express examples also read `next` only when it's a string, because the Express 4 query parser can return an object. The Next.js tab of the PKCE partial already stays on the same site, so it's unchanged. The SvelteKit confirmation tabs and the Next.js reset tab in the password guide get the same check as the other tabs. On success they redirect to the checked value. On failure, the SvelteKit tabs redirect to a fixed error page. The Next.js reset tab now matches the signup tab, so its redirect no longer carries `token_hash` and `type`. The email confirmation routes in three example apps get the same check: `examples/auth/nextjs-full`, `examples/auth/sveltekit-full`, and `examples/user-management/sveltekit-user-management`. The user management example falls back to `/account`, the page its tutorial sends users to. In the SvelteKit routes, a successful confirmation redirects straight to the checked value, and a failed one redirects to a fixed error page. Other query parameters on the confirmation link no longer carry over. The Next.js example pins TypeScript 5.9.3, because TypeScript 5.3 has no type for `URL.parse` and `next build` failed its type check. The SvelteKit tutorial embeds the user management route, so the tutorial shows the new code. ## Verification (`/test-the-docs`) Each handler was extracted by script from the MDX on this branch, on `master`, and on #51567, then mounted in a minimal app for its framework. Each app ran against a local Supabase stack in the Compose sandbox. Confirm handlers got a fresh `generateLink` token hash per case. PKCE callbacks got a real code from a PKCE magic-link sign-in through Mailpit, with the code verifier cookie. Each route ran 12 `next` cases: none, `/welcome`, `/account?tab=1`, a same-site full URL, `//evil.com`, `/\evil.com`, `https://evil.com/x`, `javascript:alert(1)`, `http://`, `/<tab>/evil.com`, `/.//evil.com`, and `/a/..//evil.com`. The same-site full URL uses the origin each server reports for itself. | Example | Framework | This branch | `master` | | --- | --- | --- | --- | | PKCE partial, SvelteKit tab | SvelteKit 2.70 + adapter-node | pass 12/12 | 2 cases off-site | | PKCE partial, Astro tab | Astro 7.4 + @astrojs/node | pass 12/12 with `Astro.*` patched (see below) | 5 cases off-site | | PKCE partial, Remix tab | Remix 2.17 | pass 12/12 | 5 cases off-site | | PKCE partial, Express tab | Express 5.3 | pass 12/12 | 2 cases off-site | | Password signup, Next.js tab | Next.js 16.5 | pass 12/12 | 5 cases off-site | | Password signup and reset, Astro tabs | Astro 7.4 | pass 12/12 each | 5 cases off-site each | | Password signup and reset, Remix tabs | Remix 2.17 | pass 12/12 each | 5 cases off-site each | | Password signup and reset, Express tabs | Express 5.3 | pass 12/12 each | 2 cases off-site each | - `next build` type-checks the Next.js handler. `tsc --strict` reports the same errors for the Remix and Astro handlers as on `master`. - Express falls back to `/` on a malformed `Host` header without crashing. - #51567 also kept every route on the same site, and sent the same-site full URL case to `/`. - The unchanged examples stay on the same site in every case. - After review, each of the 14 changed blocks ran in Node 22 against 32 `next` values. The cases include Express behind an HTTPS proxy, an object `next` from the Express 4 query parser, and custom-scheme URLs with a backslash in the path. - The SvelteKit signup and reset tabs and the Next.js reset tab also ran end to end in Node 22, with `redirect` and `verifyOtp` stubbed. A same-site full URL lands on its path, `/account?tab=1` keeps its query, and the error page URL has no `token_hash` or `type`. On `master`, the same cases redirect to `/https://…`, to `/account%3Ftab=1`, and, in the Next.js reset tab, to a URL that still carries `token_hash`. ### Example apps Each example app was built and run in the Compose sandbox against a local Supabase stack. Every case used a fresh signup token, so each request ran a real `verifyOtp` and set a session cookie. The `sveltekit-full` example has no build setup of its own, so its route ran inside the user management app. Each route ran the 12 cases above, plus the same host on the other scheme and an `ftp://` URL on the same host, plus an invalid token to check the error redirect. | Example | Framework | This branch | `master` | | --- | --- | --- | --- | | `auth/nextjs-full` | Next.js 16.5 | pass 14/14, error path passes | 5 cases off-site | | `user-management/sveltekit-user-management` | SvelteKit 2.70 | pass 14/14, error path passes | on-site, but 9 of 12 cases land on a broken path | | `auth/sveltekit-full` | SvelteKit 2.70 | pass 14/14, error path passes | on-site, but 9 of 12 cases land on a broken path | - `next build` passes. With TypeScript 5.3.3, it fails with `Property 'parse' does not exist`. - `svelte-check` reports the same 7 errors on this branch and on `master`, all in the database types and the account form. None are in the confirm route. - Behind a proxy without forwarded-host handling, `next start` sees `localhost:3000`, so a full-URL `next` falls back to the default page there. ### Found while testing, not changed here These problems are on `master` too, and they're outside the scope of this fix: - PKCE partial, Astro tab: `Astro.request` and `Astro.cookies` don't exist in an API route, so the callback returns a 500 error. Tracked in [DOCS-1841](https://linear.app/supabase/issue/DOCS-1841/make-the-astro-oauth-callback-example-run-in-an-api-route). - Password guide, Remix confirm tabs: `setAll(key, value, options)` doesn't match the `@supabase/ssr` signature, so no session cookie is set after confirming. Tracked in [DOCS-1842](https://linear.app/supabase/issue/DOCS-1842/make-the-remix-email-confirmation-examples-set-the-session-cookie). - Password guide, Express confirm tabs: no `return` after the success redirect, so the error redirect also runs. Express 5 logs `ERR_HTTP_HEADERS_SENT`, and Express 4 exits the process. Tracked in [DOCS-1843](https://linear.app/supabase/issue/DOCS-1843/stop-the-express-email-confirmation-examples-from-redirecting-twice). - PKCE partial, Express tab: the callback ignores the result of `exchangeCodeForSession`, so a missing code or a failed exchange still redirects to `next`. Tracked in [DOCS-1845](https://linear.app/supabase/issue/DOCS-1845/send-failed-code-exchanges-to-the-error-page-in-the-express-oauth). - PKCE partial and password guide, Astro tabs: `setAll` drops the cache headers that `@supabase/ssr` passes with the session cookies. Tracked in [DOCS-1846](https://linear.app/supabase/issue/DOCS-1846/apply-the-cache-headers-from-supabasessr-in-the-astro-auth-callback). - Email templates guide, server-side endpoint example: it redirects to `redirect_to` without checking it. Tracked in [DOCS-1847](https://linear.app/supabase/issue/DOCS-1847/check-redirect-to-before-redirecting-in-the-server-side-email-template). - Next.js examples in the PKCE partial, the password guide, and the WorkOS and Google sign-in guides: they import the Supabase clients from `@/utils/supabase/`, but the client guide now creates them in `lib/supabase/`. Tracked in [DOCS-1848](https://linear.app/supabase/issue/DOCS-1848/import-the-nextjs-supabase-clients-from-libsupabase-in-the-auth). ## Review category (docs PRs only) - [ ] Critical: needs a review as soon as possible - [ ] Urgent: the feature ships soon, or it's blocking something else - [ ] Moderate: good to have soon, not urgent - [x] Low: get to it when you can ## Review instructions 1. Check that each changed example only touches the `next` handling and its redirect. 2. Check the changed tabs on the preview: - [GitHub sign-in page on the preview](https://docs-git-alexisa-docs-1836-supabase.vercel.app/docs/guides/auth/social-sign-in/auth-github): the callback code for the SvelteKit, Astro, Remix, and Express tabs. Every social sign-in page includes this partial. - [Password guide on the preview](https://docs-git-alexisa-docs-1836-supabase.vercel.app/docs/guides/auth/passwords): under PKCE flow, every framework tab for signup confirmation and password reset. - [SvelteKit tutorial on the preview](https://docs-git-alexisa-docs-1836-supabase.vercel.app/docs/guides/getting-started/tutorials/with-sveltekit#confirmation-endpoint): the confirmation endpoint embeds the user management example's route. 3. Check the three confirm routes under `examples/` and the `typescript` pin in `examples/auth/nextjs-full/package.json`. ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide). Not used: only code inside existing snippets and example apps changed, no prose. The snippets were verified with `/test-the-docs`. |
||
|
|
671c94e868 |
chore(docs,kb) - Update 301 destinations to final resolution + fix some 404s (#53553)
## Context Lots of links that initially go to 301's within docs / kb. Updates these to their resolved target. Ask your Claude Code to review the new destinations programmatically. --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com> |
||
|
|
6eb40f17a7 |
docs: purge safeGetSession + getUser from auth example code (#47042)
Sweeps the example code that creating-a-client.mdx and other auth docs pull via $CodeSample, so the rendered pages match the "use getClaims()" guidance. Also adds Database type stubs and parameterizes SupabaseClient<Database> across SvelteKit and Hono examples. Fixes #40985 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Documentation** * Updated OAuth server getting-started guide to use a claims-based consent/auth gate and preserve the authorization identifier on redirect. * Added the `auth_methods` partial across framework sections in the server-side “creating a client” guide. * **Refactor** * Updated authentication examples for Hono, Next.js, and SvelteKit to rely on JWT claims for logged-in checks and protected routes. * Streamlined example auth state and UI rendering to use claims-derived information. * **Type Updates** * Improved TypeScript typing for Supabase clients and app auth data across examples, including generated database type stubs. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Chris Chinchilla <chris@chrischinchilla.com> |
||
|
|
08e9cdde5e |
docs: data api docs functions (#44412)
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Replaces "stored procedures" with "functions" for everything related to the Data API. ## Additional context It's not accurate to call database functions "stored procedures". It may have been that way before Postgres 11, but now it causes confusion because PostgREST allows functions and not stored procedures. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Standardized terminology across docs, SDK guides, CLI/config specs, examples, UI, and config comments to use "database functions" instead of "stored procedures". * Updated API docs, CLI/config descriptions, Studio UI labels, help text, empty-state and navigation copy, RPC documentation, and example text for consistency. * Adjusted explanatory text and error/help messages to reflect the revised terminology. <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
a7563e9fe6 |
docs(examples): use latest v2 of supabase-js and remove lock files (#44704)
* Use latest 2.x version of `@supabase/supabase-js` in all examples * Use `latest` version of `@supabase/ssr` in all examples * Remove lock files from examples * Add examples lock files in .gitignore The rationale is: - Lock files are not actively maintained/updated (or the versions in the package.json files for that matter) - They pin an arbitrary version (from the end-user perspective) - Removes the need to manually update the versions and reinstall - Consistency <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Chores** * Broadened Supabase SDK dependency version constraints across example projects for greater flexibility with compatible updates * Updated some SSR package dependencies to track latest releases * Added gitignore rules for dependency lock files in example directories <!-- end of auto-generated comment: release notes by coderabbit.ai --> |
||
|
|
41f9ddd70c |
docs: update setAll callbacks to accept cache headers second argument (#44240)
## What Updates all `setAll` cookie handler implementations across docs and examples to accept the new `headers` second argument introduced in `@supabase/ssr` v0.10.0 ([supabase/ssr#176](https://github.com/supabase/ssr/pull/176)). ## Why `@supabase/ssr` v0.10.0 introduced a breaking change: `setAll` now receives a required second argument `headers: Record<string, string>` alongside the cookies array. When a token refresh occurs, the library passes cache headers (`Cache-Control`, `Expires`, `Pragma`) that must be applied to the HTTP response to prevent CDN caching of auth responses. Because TypeScript allows functions with fewer parameters to satisfy a type expecting more, existing `setAll` implementations do not produce a type error when the second argument is omitted. Users who copy an outdated snippet will silently miss the CDN protection. Root cause and context: [supabase/supabase-js#1682](https://github.com/supabase/supabase-js/issues/1682) ## Changes **Proxy/middleware contexts** (where token refreshes happen) now apply the cache headers to their response: - Next.js proxy files: `supabaseResponse.headers.set(key, value)` - SvelteKit hooks: `event.setHeaders(headers)` - Hono middleware: `c.header(key, value)` - Pages Router (Express-style): `ctx.res.setHeader(key, value)` - Remix/React Router loaders and actions: applied to response headers (outer `headers` variable renamed to `responseHeaders` to avoid naming conflict with the new param) **Server Component and API route contexts** (no response object available) accept `_headers` without applying them. ## Files updated - `apps/docs/content/guides/auth/server-side/creating-a-client.mdx` (inline Astro, Remix, React Router, Express snippets) - `apps/docs/content/_partials/oauth_pkce_flow.mdx` - `apps/docs/content/guides/auth/oauth-server/getting-started.mdx` - `apps/docs/content/guides/auth/passwords.mdx` - `apps/docs/content/troubleshooting/how-to-migrate-from-supabase-auth-helpers-to-ssr-package-5NRunM.mdx` - `examples/auth/nextjs/`, `examples/auth/nextjs-full/` (proxy + server) - `examples/auth/sveltekit/`, `examples/auth/sveltekit-full/` - `examples/auth/hono/`, `examples/auth/hono-full/` - `examples/user-management/nextjs-user-management/` (proxy + server) - `examples/user-management/sveltekit-user-management/` - `examples/realtime/nextjs-authorization-demo/` (proxy + server) - `examples/realtime/nextjs-auth-presence/` (pages router) - `examples/prompts/nextjs-supabase-auth.md` |
||
|
|
d07e78a616 |
chore: Run prettier on examples folder (#43851)
This PR runs `prettier` on the `examples` folder. Depends on https://github.com/supabase/supabase/pull/43849. |
||
|
|
ae727a4659 |
docs: update supabase docs for nextjs 16 proxyts change (#40555)
* Quickstart next 16 update * Fix paths and env vars * docs: refactor nextjs server-side auth to use Proxy instead of middleware * docs: refactor nextjs server-side auth to match proxy * docs: refactor nextjs example to match Proxy * docs: refactor nextjs auth AI prompt to match Proxy * docs: refactor nextjs sentry telemetry integration to match Proxy * examples: update nextjs realtime example to match middleware * docs: refactoring guides to use nextjs proxy * examples: update nextjs-full example to match Next16 template * example: update nextjs-user-management to match nextjs 16 * docs: refactoring nextjs user-management tutorial to use typescript only * docs: refactoring nextjs quickstart, removing step 4 since this step is already included on `with-supabase` template, we can just remove this redundant step * docs: auth-helpers nextjs pages, Nextjs16 proxy disclaimer * stamp: lint * stamp: revert 'NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY' * stamp: nextjs examples, revert to use cookie options * fix(docs): typo * docs: updating nextjs-auth troubleshoot guide to match proxy * Update apps/docs/content/guides/getting-started/quickstarts/nextjs.mdx * Revert auth-helpers changes * Revert auth-helpers content * Apply suggestions from code review * Update apps/docs/content/troubleshooting/how-do-you-troubleshoot-nextjs---supabase-auth-issues-riMCZV.mdx * Update apps/docs/content/troubleshooting/how-do-you-troubleshoot-nextjs---supabase-auth-issues-riMCZV.mdx * Update apps/docs/content/troubleshooting/how-do-you-troubleshoot-nextjs---supabase-auth-issues-riMCZV.mdx * Update apps/docs/content/troubleshooting/how-do-you-troubleshoot-nextjs---supabase-auth-issues-riMCZV.mdx * Apply suggestions from code review * Prettier --------- Co-authored-by: kallebysantos <kalleby_santos@hotmail.com> |
||
|
|
534c300a7a |
docs: SSR overhaul combined client page PoC (#38405)
* Draft begins * Starte SvelteKit * Changes * Consolidate creating a client * Final draft * Update apps/docs/content/guides/auth/server-side/creating-a-client.mdx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update apps/docs/content/guides/auth/server-side/creating-a-client.mdx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Rework and simplify * Update apps/docs/content/guides/auth/server-side/creating-a-client.mdx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update apps/docs/content/guides/auth/server-side/creating-a-client.mdx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update apps/docs/content/guides/auth/server-side/creating-a-client.mdx Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * improve spacing * last * Simplify example * Prettier * Fix hono, remove old pages, and add redirects * Remove from menu * Update apps/docs/content/guides/auth/server-side/creating-a-client.mdx Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * Changes --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> Co-authored-by: Alan Daniel <stylesshjs@gmail.com> |