The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Merge branch 'master' into chore/update-sveltekit-auth-helpers-docs
Andrew Smith891e2107bc0d
diff --cc apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdxindex 33636652deb,1490c665354..33e539fad35--- a/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx+++ b/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx@@@ -15,7 -13,7 +15,7 @@@ This submodule provides convenience helThis library supports Node.js `^16.15.0`.--```sh++```sh Terminalnpm install @supabase/auth-helpers-sveltekit```@@@ -112,126 -71,11 +112,126 @@@ export const handle: Handle = async ({}```-> Note that we are specifying filterSerializedResponseHeaders here. We need to tell SvelteKit that supabase needs the content-range header.+</TabPanel>+</Tabs>++<Admonition type="info">++Note that we are specifying filterSerializedResponseHeaders here. We need to tell SvelteKit that supabase needs the content-range header.++</Admonition>++### Code Exchange Route++The `Code Exchange` route is required for the [server-side auth flow](https://supabase.com/docs/guides/auth/server-side-rendering) implemented by the SvelteKit Auth Helpers. It exchanges an auth `code` for the user's `session`, which is set as a cookie for future requests made to Supabase.++<Tabs+ scrollable+ size="small"+ type="underlined"+ defaultActiveId="js"+>+<TabPanel id="js" label="JavaScript">++Create a new file at `src/routes/auth/callback/+server.js` and populate with the following:++```jsx src/routes/auth/callback/+server.js+import { redirect } from '@sveltejs/kit'++export const GET = async ({ url, locals: { supabase } }) => {+ const code = url.searchParams.get('code')++ if (code) {+ await supabase.auth.exchangeCodeForSession(code)+ }++ throw redirect(303, '/')+}+```++</TabPanel>-### Send session to client+<TabPanel id="ts" label="TypeScript">-In order to make the session available to the UI (pages, layouts) we need to pass the session in the root layout server load function:+Create a new file at `src/routes/auth/callback/+server.ts` and populate with the following:++```tsx src/routes/auth/callback/+server.ts+import { redirect } from '@sveltejs/kit'++export const GET = async ({ url, locals: { supabase } }) => {+ const code = url.searchParams.get('code')++ if (code) {+ await supabase.auth.exchangeCodeForSession(code)+ }++ throw redirect(303, '/')+}+```++</TabPanel>+</Tabs>++### Generate types from your database++In order to get the most out of TypeScript and it's intellisense, you should import the generated Database types into the `app.d.ts` type definition file that comes with your SvelteKit project, where `import('./DatabaseDefinitions')` points to the generated types file outlined in [v2 docs here](https://supabase.com/docs/reference/javascript/release-notes#typescript-support) after you have logged in, linked, and generated types through the Supabase CLI.+- ```ts++```ts src/app.d.ts+// src/app.d.ts++import { SupabaseClient, Session } from '@supabase/supabase-js'+import { Database } from './DatabaseDefinitions'++declare global {+ namespace App {+ interface Locals {+ supabase: SupabaseClient<Database>+ getSession(): Promise<Session | null>+ }+ interface PageData {+ session: Session | null+ }+ // interface Error {}+ // interface Platform {}+ }+}+```++## Authentication++Authentication can be initiated [client](/docs/guides/auth/auth-helpers/sveltekit#client-side) or [server-side](/docs/guides/auth/auth-helpers/sveltekit#server-side). All of the [supabase-js authentication strategies](http://localhost:3001/docs/reference/javascript/auth-api) are supported with the Auth Helpers client.++<Admonition type="info">++Note: The authentication flow requires the [Code Exchange Route](/docs/guides/auth/auth-helpers/sveltekit#code-exchange-route) to exchange a `code` for the user's `session`.++</Admonition>++### Client-side++#### Send session to client++To make the session available across the UI, including pages and layouts, it is crucial to pass the session as a parameter in the root layout's server load function.++<Tabs+ scrollable+ size="small"+ type="underlined"+ defaultActiveId="js"+>+<TabPanel id="js" label="JavaScript">++```js src/routes/+layout.server.js+// src/routes/+layout.server.js+export const load = async ({ locals: { getSession } }) => {+ return {+ session: await getSession(),+ }+}+```++</TabPanel>+<TabPanel id="ts" label="TypeScript">```ts src/routes/+layout.server.ts// src/routes/+layout.server.ts