- An S3 compatible object storage service that integrates with Postgres.
+ An S3 compatible object storage service that integrates with Postgres.
- - Uses Postgres as it's datastore for storing metadata
- - Authorization rules are written as Postgres Row Level Security policies
- - Integrates with S3 as the storage backend (with more in the pipeline!)
- - Extremely lightweight and performant
+ - Uses Postgres as it's datastore for storing metadata
+ - Authorization rules are written as Postgres Row Level Security policies
+ - Integrates with S3 as the storage backend (with more in the pipeline!)
+ - Extremely lightweight and performant
diff --git a/apps/docs/docs/ref/swift/introduction.mdx b/apps/docs/docs/ref/swift/introduction.mdx
index 80dc3584bd1..1806d192617 100644
--- a/apps/docs/docs/ref/swift/introduction.mdx
+++ b/apps/docs/docs/ref/swift/introduction.mdx
@@ -13,17 +13,15 @@ hideTitle: true
-This reference documents every object and method available in Supabase's Swift library, [supabase-swift](https://github.com/supabase-community/supabase-swift). You can use supabase-swift to interact with your Postgres database, listen to database changes, invoke Deno Edge Functions, build login and user management functionality, and manage large files.
+This reference documents every object and method available in Supabase's Swift library, [supabase-swift](https://github.com/supabase-community/supabase-swift). You can use supabase-swift to interact with your Postgres database, listen to database changes, invoke Deno Edge Functions, build login and user management functionality, and manage large files.
+
+We also provide a [supabase](https://pub.dev/packages/supabase) package for non-Swift projects.
-We also provide a [supabase](https://pub.dev/packages/supabase) package for non-Swift projects.
The Swift client library is created and maintained by the Supabase community, and is not an official library. Please be tolerant of areas where the library is still being developed, and — as with all the libraries — feel free to contribute wherever you find issues.
-
- Huge thanks to official maintainer, [Maail](https://github.com/maail).
-
+
Huge thanks to official maintainer, [Maail](https://github.com/maail).
-
diff --git a/apps/docs/docs/reference/dart/initializing.mdx b/apps/docs/docs/reference/dart/initializing.mdx
index 7d914d71efd..c553c69aad7 100644
--- a/apps/docs/docs/reference/dart/initializing.mdx
+++ b/apps/docs/docs/reference/dart/initializing.mdx
@@ -30,8 +30,9 @@ final supabase = Supabase.instance.client;
### Call `initialize()` with custom headers
-You can pass `headers` to initialize your Supabase client with customer headers.
+You can pass `headers` to initialize your Supabase client with customer headers.
Here is an example of passing a custom auth header to Supabase client.
+
```dart title=main.dart
Future main() async {
await Supabase.initialize(
diff --git a/apps/docs/docs/reference/javascript/v1/initializing.mdx b/apps/docs/docs/reference/javascript/v1/initializing.mdx
index 7ea5f5cf164..c7e5361828e 100644
--- a/apps/docs/docs/reference/javascript/v1/initializing.mdx
+++ b/apps/docs/docs/reference/javascript/v1/initializing.mdx
@@ -117,7 +117,7 @@ const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key
```
By default the API server points to the `public` schema. You can enable other database schemas within the Dashboard.
-Go to `Settings > API > Schema` and add the schema which you want to expose to the API. You also need to grant `USAGE` on your new schema with the grants you desire, such as `SELECT, INSERT, UPDATE, DELETE`.
+Go to `Settings > API > Schema` and add the schema which you want to expose to the API. You also need to grant `USAGE` on your new schema with the grants you desire, such as `SELECT, INSERT, UPDATE, DELETE`.
Note: each client connection can only access a single schema, so the code above can access the `other_schema` schema but cannot access the `public` schema.
diff --git a/apps/docs/docs/reference/postgres/changing-timezones.mdx b/apps/docs/docs/reference/postgres/changing-timezones.mdx
index d05e32afc8b..aa95f4478a1 100644
--- a/apps/docs/docs/reference/postgres/changing-timezones.mdx
+++ b/apps/docs/docs/reference/postgres/changing-timezones.mdx
@@ -1,16 +1,15 @@
---
id: changing-timezones
-title: "Changing Timezones"
+title: 'Changing Timezones'
slug: changing-timezones
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/postgres.yml
---
-import Tabs from '@theme/Tabs';
-import TabsPanel from '@theme/TabsPanel';
+import Tabs from '@theme/Tabs'
+import TabsPanel from '@theme/TabsPanel'
Data types.
-
```sql
-alter database postgres
+alter database postgres
set timezone to 'America/New_York';
```
-
-
-
-
-
## Notes
- View a full list of timezones on [Wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
-
-
-
-
-
-
-
-
-
## Examples
### Change timezone
-
-
```sql
-alter database postgres
+alter database postgres
set timezone to 'America/New_York';
```
-
@@ -77,7 +59,6 @@ Get a full list of timezones supported by your database. This will return the fo
- `utc_offset`: Offset from UTC (positive means east of Greenwich)
- `is_dst`: True if currently observing daylight savings
-
@@ -108,12 +88,11 @@ Use `ilike` (case insensitive search) to find specific timezones.
```sql
-select *
-from pg_timezone_names()
+select *
+from pg_timezone_names()
where name ilike '%york%';
```
-
-
\ No newline at end of file
+
diff --git a/apps/docs/docs/reference/postgres/columns.mdx b/apps/docs/docs/reference/postgres/columns.mdx
index 0ccaa830381..22a00b3462f 100644
--- a/apps/docs/docs/reference/postgres/columns.mdx
+++ b/apps/docs/docs/reference/postgres/columns.mdx
@@ -1,16 +1,15 @@
---
id: columns
-title: "Columns"
+title: 'Columns'
slug: columns
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/postgres.yml
---
-import Tabs from '@theme/Tabs';
-import TabsPanel from '@theme/TabsPanel';
+import Tabs from '@theme/Tabs'
+import TabsPanel from '@theme/TabsPanel'
Creating columns.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
## Examples
### During table creation
-
-
### Create column
-
-
-
\ No newline at end of file
+
diff --git a/apps/docs/docs/reference/postgres/connection-strings.mdx b/apps/docs/docs/reference/postgres/connection-strings.mdx
index 12e4f919c9c..46f50663f00 100644
--- a/apps/docs/docs/reference/postgres/connection-strings.mdx
+++ b/apps/docs/docs/reference/postgres/connection-strings.mdx
@@ -1,16 +1,15 @@
---
id: connection-strings
-title: "Connection Strings"
+title: 'Connection Strings'
slug: connection-strings
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/postgres.yml
---
-import Tabs from '@theme/Tabs';
-import TabsPanel from '@theme/TabsPanel';
+import Tabs from '@theme/Tabs'
+import TabsPanel from '@theme/TabsPanel'
There are various ways to connect to your database, depending on the configuration of your Postgres instance and the tool which you are connecting with.
-
-
-
-
-
## Notes
- [Official Documentation](https://www.postgresql.org/docs/current/libpq-connect.html).
- Avoid using special characters usernames and passwords. If you use special characters in a connection URL, you'll need to URL encode any special characters.
-
-
-
-
-
-
-
-
-
## Examples
### Basic connection string
-If you're using a default setup, your postgres connection string will likely be in the format:
+If you're using a default setup, your postgres connection string will likely be in the format:
`postgres://{user}:{password}@{host}:{port}/{database_name}`
-
@@ -89,7 +72,6 @@ See full [documentation](http://jdbc.postgresql.org/documentation/head/connect.h
jdbc:postgresql://{host}:{port}/{database_name}
```
-
@@ -109,7 +91,6 @@ See full [documentation](http://npgsql.projects.postgresql.org/docs/manual/UserM
Server=host;Port=5432;User Id=username;Password=secret;Database=database_name;
```
-
@@ -129,7 +110,6 @@ See full [documentation](http://php.net/manual/en/book.pgsql.php).
host=hostname port=5432 dbname=databasename user=username password=secret
```
-
-
\ No newline at end of file
+
diff --git a/apps/docs/docs/reference/postgres/database-passwords.mdx b/apps/docs/docs/reference/postgres/database-passwords.mdx
index 9f58234b1a1..67355a9250f 100644
--- a/apps/docs/docs/reference/postgres/database-passwords.mdx
+++ b/apps/docs/docs/reference/postgres/database-passwords.mdx
@@ -1,40 +1,19 @@
---
id: database-passwords
-title: "Database Passwords"
+title: 'Database Passwords'
slug: database-passwords
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/postgres.yml
---
-import Tabs from '@theme/Tabs';
-import TabsPanel from '@theme/TabsPanel';
+import Tabs from '@theme/Tabs'
+import TabsPanel from '@theme/TabsPanel'
Manage the passwords of your database users using any super user.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
## Examples
### Password reset
-
-
```sql
-alter user postgres
+alter user postgres
with password 'new_password';
```
-
-
\ No newline at end of file
+
diff --git a/apps/docs/docs/reference/postgres/database-users.mdx b/apps/docs/docs/reference/postgres/database-users.mdx
index 8ccca2ce94a..55577d615d5 100644
--- a/apps/docs/docs/reference/postgres/database-users.mdx
+++ b/apps/docs/docs/reference/postgres/database-users.mdx
@@ -1,40 +1,19 @@
---
id: database-users
-title: "Database Users"
+title: 'Database Users'
slug: database-users
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/postgres.yml
---
-import Tabs from '@theme/Tabs';
-import TabsPanel from '@theme/TabsPanel';
+import Tabs from '@theme/Tabs'
+import TabsPanel from '@theme/TabsPanel'
Users and Roles are almost interchangeable.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
## Examples
### Create New User
-
-
-
\ No newline at end of file
+
diff --git a/apps/docs/docs/reference/postgres/index.mdx b/apps/docs/docs/reference/postgres/index.mdx
index b6641472785..9fe059e4e87 100644
--- a/apps/docs/docs/reference/postgres/index.mdx
+++ b/apps/docs/docs/reference/postgres/index.mdx
@@ -1,15 +1,14 @@
---
id: index
-title: "Getting started"
+title: 'Getting started'
slug: getting-started
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/postgres.yml
---
-import Tabs from '@theme/Tabs';
-import TabsPanel from '@theme/TabsPanel';
+import Tabs from '@theme/Tabs'
+import TabsPanel from '@theme/TabsPanel'
-
-PostgreSQL, also known as Postgres, is a free and open-source relational
-database management system emphasizing extensibility and SQL compliance.
-It was originally named POSTGRES, referring to its origins as a successor
-to the Ingres database developed at the University of California, Berkeley.
\ No newline at end of file
+PostgreSQL, also known as Postgres, is a free and open-source relational
+database management system emphasizing extensibility and SQL compliance.
+It was originally named POSTGRES, referring to its origins as a successor
+to the Ingres database developed at the University of California, Berkeley.
diff --git a/apps/docs/docs/reference/postgres/publications.mdx b/apps/docs/docs/reference/postgres/publications.mdx
index 87559a38e34..8c7d19b4e75 100644
--- a/apps/docs/docs/reference/postgres/publications.mdx
+++ b/apps/docs/docs/reference/postgres/publications.mdx
@@ -1,42 +1,22 @@
---
id: publications
-title: "Publications"
+title: 'Publications'
slug: publications
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/postgres.yml
---
-import Tabs from '@theme/Tabs';
-import TabsPanel from '@theme/TabsPanel';
+import Tabs from '@theme/Tabs'
+import TabsPanel from '@theme/TabsPanel'
-Publications are a way of grouping changes generated from a table or a group of tables.
+Publications are a way of grouping changes generated from a table or a group of tables.
These changes can then be sent to other systems (usually another Postgres database).
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
## Examples
### Create a Publication
This publication will contain all changes to all tables.
-
```sql
-create publication publication_name
+create publication publication_name
for all tables;
```
-
### Create a Publication which listens to individual tables
-
-
```sql
-create publication publication_name
+create publication publication_name
for table table_one, table_two;
```
-
### Add tables to an existing publication
-
-
```sql
-alter publication publication_name
+alter publication publication_name
add table table_name;
```
-
### Listens to inserts only
-
-
```sql
-create publication publication_name
+create publication publication_name
for all tables
with (publish = 'insert');
```
-
### Listens to updates only
-
-
```sql
-create publication publication_name
+create publication publication_name
for all tables
with (publish = 'update');
```
-
### Listens to deletions only
-
-
```sql
-create publication publication_name
+create publication publication_name
for all tables
with (publish = 'delete');
```
-
### Remove a Publication
-
-
@@ -186,7 +147,6 @@ drop publication if exists publication_name;
If you are planning to re-create a publication, it's best to do it in a transaction to ensure the operation succeeds.
-
```sql
-begin;
+begin;
-- remove the realtime publication
- drop publication if exists publication_name;
+ drop publication if exists publication_name;
-- re-create the publication but don't enable it for any tables
- create publication publication_name;
+ create publication publication_name;
commit;
```
-
-
\ No newline at end of file
+
diff --git a/apps/docs/docs/reference/postgres/schemas.mdx b/apps/docs/docs/reference/postgres/schemas.mdx
index ad4fbf6d9ef..747668d3fa3 100644
--- a/apps/docs/docs/reference/postgres/schemas.mdx
+++ b/apps/docs/docs/reference/postgres/schemas.mdx
@@ -1,19 +1,18 @@
---
id: schemas
-title: "Schemas"
+title: 'Schemas'
slug: schemas
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/postgres.yml
---
-import Tabs from '@theme/Tabs';
-import TabsPanel from '@theme/TabsPanel';
+import Tabs from '@theme/Tabs'
+import TabsPanel from '@theme/TabsPanel'
-Schemas are like "folders". They help to keep your database organized.
+Schemas are like "folders". They help to keep your database organized.
-Schemas are particularly useful for security. You can set different permissions on each schema.
+Schemas are particularly useful for security. You can set different permissions on each schema.
For example, you might want to use a `public` schema for user-facing data, and an `auth` schema for all logins and secured data.
-
-
-
-
-
## Notes
- Schemas contain [tables](/docs/reference/postgres/tables), columns, triggers, functions, etc.
- Postgres comes with a `public` schema set up by default.
- It is best practice to use lowercase and underscores when naming schemas. For example: `schema_name`, not `Schema Name`.
-
-
-
-
-
-
-
-
-
## Examples
### Creating a schema
-
-
### Removing a schema
-
-
@@ -96,7 +75,6 @@ drop schema if exists schema_name;
Although it's not recommended, you can use uppercase and spaces when naming your schema by wrapping the name with double-quotes.
As a result, you will always need to use double-quotes when referencing your schema.
-
-
\ No newline at end of file
+
diff --git a/apps/docs/docs/reference/postgres/tables.mdx b/apps/docs/docs/reference/postgres/tables.mdx
index 05df802a961..d33152a8887 100644
--- a/apps/docs/docs/reference/postgres/tables.mdx
+++ b/apps/docs/docs/reference/postgres/tables.mdx
@@ -1,19 +1,18 @@
---
id: tables
-title: "Tables"
+title: 'Tables'
slug: tables
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/postgres.yml
---
-import Tabs from '@theme/Tabs';
-import TabsPanel from '@theme/TabsPanel';
+import Tabs from '@theme/Tabs'
+import TabsPanel from '@theme/TabsPanel'
Tables are similar to excel spreadsheets. They contain columns & rows of data. There are a few key differences from a spreadsheet however:
- Every column is a strict type of data. When you set up a column, you must define what "data type" it is.
- Tables can be joined together through relationships. For example you can have a "users" table, which is joined to a "teams" table.
-
-
-
-
-
## Notes
-- Tables contain columns, rows, triggers, comments,
+- Tables contain columns, rows, triggers, comments,
- It is best practice to use lowercase and underscores when naming tables. For example: `table_name`, not `Table Name`.
- Tables belong to [schemas](/docs/reference/postgres/schemas). If you don't explicitly pass the schema, Postgres will assume that you want to create the table in the `public` schema.
-
-
-
-
-
-
-
-
-
## Examples
### Create table
-
-
### Primary keys using multiple columns
-
-
### Multiple foreign keys to the same table
-
-
### Delete a table
-
-
-
\ No newline at end of file
+
diff --git a/apps/docs/pages/guides/api.mdx b/apps/docs/pages/guides/api.mdx
index 3b518ced47b..390dcadd33d 100644
--- a/apps/docs/pages/guides/api.mdx
+++ b/apps/docs/pages/guides/api.mdx
@@ -32,6 +32,7 @@ Supabase provides a RESTful API using [PostgREST](https://postgrest.org/). This
It provides everything you need from a CRUD API at the URL `https://.supabase.co/rest/v1/`.
The REST interface is automatically reflected from your database's schema and supports:
+
- Basic CRUD operations (Create/Read/Update/Delete)
- Arbitrarily deep relationships among tables/views, functions that return table types can also nest related tables/views.
- Works with Postgres Views, Materialized Views and Foreign Tables
@@ -42,6 +43,7 @@ The REST interface is automatically reflected from your database's schema and su
The REST API resolves all requests to a single SQL statement leading to fast response times and high throughput.
Reference:
+
- [Docs](https://postgrest.org/)
- [Source Code](https://github.com/PostgREST/postgrest)
@@ -52,6 +54,7 @@ You can introspect and query the GraphQL API of an existing Supabase project wit
or navigate there manually at `API Docs > GraphQL > GraphiQL`.
The GraphQL interface is automatically reflected from your database's schema and supports:
+
- Basic CRUD operations (Create/Read/Update/Delete)
- Support for Tables, Views, Materialized Views, and Foreign Tables
- Arbitrarily deep relationships among tables/views
@@ -61,6 +64,7 @@ The GraphQL interface is automatically reflected from your database's schema and
The GraphQL API resolves all requests in a single round-trip leading to fast response times and high throughput.
Reference:
+
- [Docs](https://supabase.github.io/pg_graphql/)
- [Source Code](https://github.com/supabase/pg_graphql)
diff --git a/apps/docs/pages/guides/api/joins-and-nesting.mdx b/apps/docs/pages/guides/api/joins-and-nesting.mdx
index 205e1ceece0..1ee2d396193 100644
--- a/apps/docs/pages/guides/api/joins-and-nesting.mdx
+++ b/apps/docs/pages/guides/api/joins-and-nesting.mdx
@@ -40,24 +40,25 @@ Let's use an example database that stores `countries` and `cities`:
```sql
-create table
- countries ("id" serial primary key, "name" text);
+create table countries (
+ "id" serial primary key,
+ "name" text
+);
-insert into
- countries (id, name)
+insert into countries
+ (id, name)
values
(1, 'United Kingdom'),
(2, 'United States');
-create table
- cities (
- "id" serial primary key,
- "name" text,
- "country_id" int references "countries"
- );
+create table cities (
+ "id" serial primary key,
+ "name" text,
+ "country_id" int references "countries"
+);
-insert into
- cities (name, country_id)
+insert into cities
+ (name, country_id)
values
('London', 1),
('Manchester', 1),
@@ -130,18 +131,21 @@ GET https://[REF].supabase.co/rest/v1/countries?select=id,name,cities(id,name)
The Serverless APIs will detect many-to-many joins. For example, if you have a database which stored teams of users (where each user could belong to many teams):
```sql
-create table
- users ("id" serial primary key, "name" text);
+create table users (
+ "id" serial primary key,
+ "name" text
+);
-create table
- teams ("id" serial primary key, "team_name" text);
+create table teams (
+ "id" serial primary key,
+ "team_name" text
+);
-create table
- members (
- "user_id" int references users,
- "team_id" int references teams,
- primary key(user_id, team_id)
- );
+create table members (
+ "user_id" int references users,
+ "team_id" int references teams,
+ primary key (user_id, team_id)
+);
```
In these cases you don't need to explicitly define the joining table (members). If we wanted to fetch all the teams and the members in each team:
diff --git a/apps/docs/pages/guides/api/securing-your-api.mdx b/apps/docs/pages/guides/api/securing-your-api.mdx
index 70fa2ef38ae..5887a6a33b8 100644
--- a/apps/docs/pages/guides/api/securing-your-api.mdx
+++ b/apps/docs/pages/guides/api/securing-your-api.mdx
@@ -49,10 +49,8 @@ To confirm that safeupdate is enabled for API queries, run the following query:
select
usename,
useconfig
-from
- pg_shadow
-where
- usename = 'authenticator';
+from pg_shadow
+where usename = 'authenticator';
```
The expected value for `useconfig` should be:
diff --git a/apps/docs/pages/guides/auth/auth-helpers/auth-ui.mdx b/apps/docs/pages/guides/auth/auth-helpers/auth-ui.mdx
index 66e26a91c2d..adf50a3de10 100644
--- a/apps/docs/pages/guides/auth/auth-helpers/auth-ui.mdx
+++ b/apps/docs/pages/guides/auth/auth-helpers/auth-ui.mdx
@@ -94,7 +94,7 @@ The Auth component is currently shipped with the following views:
- Update password
- Forgotten password
-We are planning on adding more views in the future. Follow along on that [repo](https://github.com/supabase/auth-ui).
+We are planning on adding more views in the future. Follow along on that [repo](https://github.com/supabase/auth-ui).
## Customization
diff --git a/apps/docs/pages/guides/auth/auth-helpers/remix.mdx b/apps/docs/pages/guides/auth/auth-helpers/remix.mdx
index 621c2d473f8..7ff90a03904 100644
--- a/apps/docs/pages/guides/auth/auth-helpers/remix.mdx
+++ b/apps/docs/pages/guides/auth/auth-helpers/remix.mdx
@@ -424,9 +424,7 @@ And then use the revalidator, inside the `onAuthStateChange` hook.
const { env, session } = useLoaderData()
const { revalidate } = useRevalidator()
-const [supabase] = useState(() =>
- createBrowserClient(env.SUPABASE_URL, env.SUPABASE_ANON_KEY)
-)
+const [supabase] = useState(() => createBrowserClient(env.SUPABASE_URL, env.SUPABASE_ANON_KEY))
const serverAccessToken = session?.access_token
@@ -464,7 +462,7 @@ useEffect(() => {
const {
data: { subscription },
} = supabase.auth.onAuthStateChange((event, session) => {
- if (event !== "INITIAL_SESSION" && session?.access_token !== serverAccessToken) {
+ if (event !== 'INITIAL_SESSION' && session?.access_token !== serverAccessToken) {
// server and client are out of sync.
revalidate()
}
diff --git a/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx b/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx
index 424ed29ee0a..6696b99b73e 100644
--- a/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx
+++ b/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx
@@ -35,19 +35,16 @@ Create a server supabase client in a handle hook:
```ts title=src/hooks.server.ts
// src/hooks.server.ts
-import {
- PUBLIC_SUPABASE_URL,
- PUBLIC_SUPABASE_ANON_KEY
-} from '$env/static/public';
-import { createSupabaseServerClient } from '@supabase/auth-helpers-sveltekit';
-import type { Handle } from '@sveltejs/kit';
+import { PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY } from '$env/static/public'
+import { createSupabaseServerClient } from '@supabase/auth-helpers-sveltekit'
+import type { Handle } from '@sveltejs/kit'
export const handle: Handle = async ({ event, resolve }) => {
event.locals.supabase = createSupabaseServerClient({
supabaseUrl: PUBLIC_SUPABASE_URL,
supabaseKey: PUBLIC_SUPABASE_ANON_KEY,
- event
- });
+ event,
+ })
/**
* a little helper that is written for convenience so that instead
@@ -56,10 +53,10 @@ export const handle: Handle = async ({ event, resolve }) => {
*/
event.locals.getSession = async () => {
const {
- data: { session }
- } = await event.locals.supabase.auth.getSession();
- return session;
- };
+ data: { session },
+ } = await event.locals.supabase.auth.getSession()
+ return session
+ }
return resolve(event, {
/**
@@ -68,10 +65,10 @@ export const handle: Handle = async ({ event, resolve }) => {
* https://github.com/sveltejs/kit/issues/8061
*/
filterSerializedResponseHeaders(name) {
- return name === 'content-range';
- }
- });
-};
+ return name === 'content-range'
+ },
+ })
+}
```
> Note that we are specifying filterSerializedResponseHeaders here. We need to tell SvelteKit that supabase needs the content-range header.
@@ -82,13 +79,13 @@ In order to make the session available to the UI (pages, layouts) we need to pas
```ts title=src/routes/+layout.server.ts
// src/routes/+layout.server.ts
-import type { LayoutServerLoad } from './$types';
+import type { LayoutServerLoad } from './$types'
export const load: LayoutServerLoad = async ({ locals: { getSession } }) => {
return {
- session: await getSession()
- };
-};
+ session: await getSession(),
+ }
+}
```
### Shared Load functions and pages
@@ -97,30 +94,27 @@ To be able to use Supabase in shared load functions and inside pages you need to
```ts
// src/routes/+layout.ts
-import {
- PUBLIC_SUPABASE_ANON_KEY,
- PUBLIC_SUPABASE_URL
-} from '$env/static/public';
-import { createSupabaseLoadClient } from '@supabase/auth-helpers-sveltekit';
-import type { LayoutLoad } from './$types';
-import type { Database } from '../DatabaseDefinitions';
+import { PUBLIC_SUPABASE_ANON_KEY, PUBLIC_SUPABASE_URL } from '$env/static/public'
+import { createSupabaseLoadClient } from '@supabase/auth-helpers-sveltekit'
+import type { LayoutLoad } from './$types'
+import type { Database } from '../DatabaseDefinitions'
export const load: LayoutLoad = async ({ fetch, data, depends }) => {
- depends('supabase:auth');
+ depends('supabase:auth')
const supabase = createSupabaseLoadClient({
supabaseUrl: PUBLIC_SUPABASE_URL,
supabaseKey: PUBLIC_SUPABASE_ANON_KEY,
event: { fetch },
- serverSession: data.session
- });
+ serverSession: data.session,
+ })
const {
- data: { session }
- } = await supabase.auth.getSession();
+ data: { session },
+ } = await supabase.auth.getSession()
- return { supabase, session };
-};
+ return { supabase, session }
+}
```
Access the client inside pages by `$page.data.supabase` or `data.supabase` when using `export let data: PageData`.
@@ -169,17 +163,17 @@ In order to get the most out of TypeScript and it's intellisense, you should imp
```ts
// src/app.d.ts
-import { SupabaseClient, Session } from '@supabase/supabase-js';
-import { Database } from './DatabaseDefinitions';
+import { SupabaseClient, Session } from '@supabase/supabase-js'
+import { Database } from './DatabaseDefinitions'
declare global {
namespace App {
interface Locals {
- supabase: SupabaseClient;
- getSession(): Promise;
+ supabase: SupabaseClient
+ getSession(): Promise
}
interface PageData {
- session: Session | null;
+ session: Session | null
}
// interface Error {}
// interface Platform {}
@@ -193,24 +187,24 @@ For [row level security](https://supabase.com/docs/guides/auth/row-level-securit
```html
{#if data.session}
- client-side data fetching with RLS
- {JSON.stringify(loadedData, null, 2)}
+client-side data fetching with RLS
+{JSON.stringify(loadedData, null, 2)}
{/if}
```
@@ -219,10 +213,10 @@ For [row level security](https://supabase.com/docs/guides/auth/row-level-securit
```html
Protected content for {user.email}
@@ -232,21 +226,21 @@ For [row level security](https://supabase.com/docs/guides/auth/row-level-securit
```ts
// src/routes/profile/+page.ts
-import type { PageLoad } from './$types';
-import { redirect } from '@sveltejs/kit';
+import type { PageLoad } from './$types'
+import { redirect } from '@sveltejs/kit'
export const load: PageLoad = async ({ parent }) => {
- const { supabase, session } = await parent();
+ const { supabase, session } = await parent()
if (!session) {
- throw redirect(303, '/');
+ throw redirect(303, '/')
}
- const { data: tableData } = await supabase.from('test').select('*');
+ const { data: tableData } = await supabase.from('test').select('*')
return {
user: session.user,
- tableData
- };
-};
+ tableData,
+ }
+}
```
## Protecting API routes
@@ -255,21 +249,19 @@ Wrap an API Route to check that the user has a valid session. If they're not log
```ts
// src/routes/api/protected-route/+server.ts
-import type { RequestHandler } from './$types';
-import { json, error } from '@sveltejs/kit';
+import type { RequestHandler } from './$types'
+import { json, error } from '@sveltejs/kit'
-export const GET: RequestHandler = async ({
- locals: { supabase, getSession }
-}) => {
- const session = await getSession();
+export const GET: RequestHandler = async ({ locals: { supabase, getSession } }) => {
+ const session = await getSession()
if (!session) {
// the user is not signed in
- throw error(401, { message: 'Unauthorized' });
+ throw error(401, { message: 'Unauthorized' })
}
- const { data } = await supabase.from('test').select('*');
+ const { data } = await supabase.from('test').select('*')
- return json({ data });
-};
+ return json({ data })
+}
```
If you visit `/api/protected-route` without a valid session cookie, you will get a 401 response.
@@ -280,35 +272,35 @@ Wrap an Action to check that the user has a valid session. If they're not logged
```ts
// src/routes/posts/+page.server.ts
-import type { Actions } from './$types';
-import { error, fail } from '@sveltejs/kit';
+import type { Actions } from './$types'
+import { error, fail } from '@sveltejs/kit'
export const actions: Actions = {
createPost: async ({ request, locals: { supabase, getSession } }) => {
- const session = await getSession();
+ const session = await getSession()
if (!session) {
// the user is not signed in
- throw error(401, { message: 'Unauthorized' });
+ throw error(401, { message: 'Unauthorized' })
}
// we are save, let the user create the post
- const formData = await request.formData();
- const content = formData.get('content');
+ const formData = await request.formData()
+ const content = formData.get('content')
const { error: createPostError, data: newPost } = await supabase
.from('posts')
- .insert({ content });
+ .insert({ content })
if (createPostError) {
return fail(500, {
- supabaseErrorMessage: createPostError.message
- });
+ supabaseErrorMessage: createPostError.message,
+ })
}
return {
- newPost
- };
- }
-};
+ newPost,
+ }
+ },
+}
```
If you try to submit a form with the action `?/createPost` without a valid session cookie, you will get a 401 error response.
@@ -316,47 +308,47 @@ If you try to submit a form with the action `?/createPost` without a valid sessi
## Saving and deleting the session
```ts
-import type { Actions } from './$types';
-import { fail, redirect } from '@sveltejs/kit';
-import { AuthApiError } from '@supabase/supabase-js';
+import type { Actions } from './$types'
+import { fail, redirect } from '@sveltejs/kit'
+import { AuthApiError } from '@supabase/supabase-js'
export const actions: Actions = {
signin: async ({ request, locals: { supabase } }) => {
- const formData = await request.formData();
+ const formData = await request.formData()
- const email = formData.get('email') as string;
- const password = formData.get('password') as string;
+ const email = formData.get('email') as string
+ const password = formData.get('password') as string
const { error } = await supabase.auth.signInWithPassword({
email,
- password
- });
+ password,
+ })
if (error) {
if (error instanceof AuthApiError && error.status === 400) {
return fail(400, {
error: 'Invalid credentials.',
values: {
- email
- }
- });
+ email,
+ },
+ })
}
return fail(500, {
error: 'Server error. Try again later.',
values: {
- email
- }
- });
+ email,
+ },
+ })
}
- throw redirect(303, '/dashboard');
+ throw redirect(303, '/dashboard')
},
signout: async ({ locals: { supabase } }) => {
- await supabase.auth.signOut();
- throw redirect(303, '/');
- }
-};
+ await supabase.auth.signOut()
+ throw redirect(303, '/')
+ },
+}
```
## Protecting multiple routes
@@ -366,33 +358,30 @@ protect multiple routes at once.
```ts
// src/hooks.server.ts
-import type { RequestHandler } from './$types';
-import { redirect, error } from '@sveltejs/kit';
+import type { RequestHandler } from './$types'
+import { redirect, error } from '@sveltejs/kit'
export const handle: Handle = async ({ event, resolve }) => {
// protect requests to all routes that start with /protected-routes
if (event.url.pathname.startsWith('/protected-routes')) {
- const session = await event.locals.getSession();
+ const session = await event.locals.getSession()
if (!session) {
// the user is not signed in
- throw redirect(303, '/');
+ throw redirect(303, '/')
}
}
// protect POST requests to all routes that start with /protected-posts
- if (
- event.url.pathname.startsWith('/protected-posts') &&
- event.request.method === 'POST'
- ) {
- const session = await event.locals.getSession();
+ if (event.url.pathname.startsWith('/protected-posts') && event.request.method === 'POST') {
+ const session = await event.locals.getSession()
if (!session) {
// the user is not signed in
- throw error(303, '/');
+ throw error(303, '/')
}
}
- return resolve(event);
-};
+ return resolve(event)
+}
```
## Migrate from 0.8.x to 0.9 [#migration]
@@ -425,19 +414,16 @@ export const supabaseClient = createClient(env.PUBLIC_SUPABASE_URL, env.PUBLIC_S
```js title=src/hooks.server.ts
// src/hooks.server.ts
-import {
- PUBLIC_SUPABASE_URL,
- PUBLIC_SUPABASE_ANON_KEY
-} from '$env/static/public';
-import { createSupabaseServerClient } from '@supabase/auth-helpers-sveltekit';
-import type { Handle } from '@sveltejs/kit';
+import { PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY } from '$env/static/public'
+import { createSupabaseServerClient } from '@supabase/auth-helpers-sveltekit'
+import type { Handle } from '@sveltejs/kit'
export const handle: Handle = async ({ event, resolve }) => {
event.locals.supabase = createSupabaseServerClient({
supabaseUrl: PUBLIC_SUPABASE_URL,
supabaseKey: PUBLIC_SUPABASE_ANON_KEY,
- event
- });
+ event,
+ })
/**
* a little helper that is written for convenience so that instead
@@ -446,10 +432,10 @@ export const handle: Handle = async ({ event, resolve }) => {
*/
event.locals.getSession = async () => {
const {
- data: { session }
- } = await event.locals.supabase.auth.getSession();
- return session;
- };
+ data: { session },
+ } = await event.locals.supabase.auth.getSession()
+ return session
+ }
return resolve(event, {
/**
@@ -458,10 +444,10 @@ export const handle: Handle = async ({ event, resolve }) => {
* https://github.com/sveltejs/kit/issues/8061
*/
filterSerializedResponseHeaders(name) {
- return name === 'content-range';
- }
- });
-};
+ return name === 'content-range'
+ },
+ })
+}
```
@@ -469,7 +455,7 @@ export const handle: Handle = async ({ event, resolve }) => {
### Initialize the client [#migration-initialize-client]
-In order to use the Supabase library in your client code you will need to setup a shared load function inside the root `+layout.ts` and create a `+layout.svelte` to handle our event listening for Auth events.
+In order to use the Supabase library in your client code you will need to setup a shared load function inside the root `+layout.ts` and create a `+layout.svelte` to handle our event listening for Auth events.
{
- depends('supabase:auth');
+ depends('supabase:auth')
const supabase = createSupabaseLoadClient({
supabaseUrl: PUBLIC_SUPABASE_URL,
supabaseKey: PUBLIC_SUPABASE_ANON_KEY,
event: { fetch },
- serverSession: data.session
- });
+ serverSession: data.session,
+ })
const {
- data: { session }
- } = await supabase.auth.getSession();
+ data: { session },
+ } = await supabase.auth.getSession()
- return { supabase, session };
-};
+ return { supabase, session }
+}
```
```svelte title=src/routes/+layout.svelte
@@ -605,17 +588,17 @@ declare namespace App {
```ts title=src/app.d.ts
// src/app.d.ts
-import { SupabaseClient, Session } from '@supabase/supabase-js';
-import { Database } from './DatabaseDefinitions';
+import { SupabaseClient, Session } from '@supabase/supabase-js'
+import { Database } from './DatabaseDefinitions'
declare global {
namespace App {
interface Locals {
- supabase: SupabaseClient;
- getSession(): Promise;
+ supabase: SupabaseClient
+ getSession(): Promise
}
interface PageData {
- session: Session | null;
+ session: Session | null
}
// interface Error {}
// interface Platform {}
@@ -675,10 +658,10 @@ export const load: PageLoad = async (event) => {
```html title=src/routes/profile/+page.svelte
Protected content for {user.email}
@@ -688,21 +671,21 @@ export const load: PageLoad = async (event) => {
```ts title=src/routes/profile/+page.ts
// src/routes/profile/+page.ts
-import type { PageLoad } from './$types';
-import { redirect } from '@sveltejs/kit';
+import type { PageLoad } from './$types'
+import { redirect } from '@sveltejs/kit'
export const load: PageLoad = async ({ parent }) => {
- const { supabase, session } = await parent();
+ const { supabase, session } = await parent()
if (!session) {
- throw redirect(303, '/');
+ throw redirect(303, '/')
}
- const { data: tableData } = await supabase.from('test').select('*');
+ const { data: tableData } = await supabase.from('test').select('*')
return {
user: session.user,
- tableData
- };
-};
+ tableData,
+ }
+}
```