From 7ce8579358dc5d46040d78a15709d697280e21af Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Fri, 28 Apr 2023 15:55:49 -0600 Subject: [PATCH] chore(prettier): fix sql & format mdx files --- .prettierrc | 4 +- .../MDX/social_provider_settings_supabase.mdx | 2 +- .../docs/ref/javascript/v1/upgrade-guide.mdx | 28 +- .../ref/self-hosting-auth/introduction.mdx | 4 +- .../ref/self-hosting-storage/introduction.mdx | 10 +- apps/docs/docs/ref/swift/introduction.mdx | 10 +- .../docs/docs/reference/dart/initializing.mdx | 3 +- .../reference/javascript/v1/initializing.mdx | 2 +- .../reference/postgres/changing-timezones.mdx | 39 +-- apps/docs/docs/reference/postgres/columns.mdx | 32 +- .../reference/postgres/connection-strings.mdx | 34 +- .../reference/postgres/database-passwords.mdx | 32 +- .../reference/postgres/database-users.mdx | 30 +- apps/docs/docs/reference/postgres/index.mdx | 15 +- .../docs/reference/postgres/publications.mdx | 69 +--- apps/docs/docs/reference/postgres/schemas.mdx | 35 +- apps/docs/docs/reference/postgres/tables.mdx | 41 +-- apps/docs/pages/guides/api.mdx | 4 + .../pages/guides/api/joins-and-nesting.mdx | 48 +-- .../pages/guides/api/securing-your-api.mdx | 6 +- .../guides/auth/auth-helpers/auth-ui.mdx | 2 +- .../pages/guides/auth/auth-helpers/remix.mdx | 6 +- .../guides/auth/auth-helpers/sveltekit.mdx | 322 ++++++++---------- .../pages/guides/auth/quickstarts/react.mdx | 2 +- .../guides/auth/social-login/auth-github.mdx | 2 +- .../pages/guides/auth/sso/auth-sso-saml.mdx | 21 +- .../guides/database/extensions/pgsodium.mdx | 14 +- .../guides/database/postgres/indexes.mdx | 16 +- .../getting-started/tutorials/with-expo.mdx | 11 +- .../getting-started/tutorials/with-nextjs.mdx | 2 +- .../tutorials/with-solidjs.mdx | 4 +- .../tutorials/with-sveltekit.mdx | 197 ++++++----- .../getting-started/tutorials/with-vue-3.mdx | 2 +- apps/docs/pages/guides/platform/backups.mdx | 4 +- apps/docs/pages/guides/platform/logs.mdx | 2 +- .../migrating-and-upgrading-projects.mdx | 7 +- apps/docs/pages/guides/platform/spend-cap.mdx | 4 +- .../guides/realtime/extensions/broadcast.mdx | 6 +- .../realtime/extensions/postgres-changes.mdx | 14 +- apps/docs/pages/guides/realtime/protocol.mdx | 3 +- apps/docs/pages/guides/resources/glossary.mdx | 1 - .../migrating-to-supabase/amazon-rds.mdx | 22 +- apps/docs/pages/guides/storage/cdn.mdx | 1 - .../guides/storage/image-transformations.mdx | 26 +- .../_blog/2020-07-09-postgresql-templates.mdx | 2 +- .../www/_blog/2020-11-18-postgresql-views.mdx | 64 ++-- ...2021-02-27-cracking-postgres-interview.mdx | 25 +- .../2021-03-05-postgres-as-a-cron-server.mdx | 3 +- .../www/_blog/2021-03-30-supabase-storage.mdx | 9 +- .../2021-11-28-whats-new-in-postgres-14.mdx | 38 +-- apps/www/_blog/2021-11-30-supabase-studio.mdx | 48 +-- ...ltime-row-level-security-in-postgresql.mdx | 3 +- apps/www/_blog/2021-12-03-pg-graphql.mdx | 18 +- apps/www/_blog/2022-03-08-audit.mdx | 27 +- .../2022-03-29-graphql-now-available.mdx | 26 +- ...ase-realtime-with-multiplayer-features.mdx | 3 +- ...022-06-15-loading-data-supabase-python.mdx | 25 +- ...sualizing-supabase-data-using-metabase.mdx | 9 +- ...0-flutter-tutorial-building-a-chat-app.mdx | 2 +- .../2022-07-18-seen-by-in-postgresql.mdx | 15 +- ...idate-slackbot-to-consolidate-messages.mdx | 19 +- apps/www/_blog/2022-08-16-supabase-js-v2.mdx | 5 +- apps/www/_blog/2022-08-19-postgrest-v10.mdx | 51 +-- apps/www/_blog/2022-08-19-supabase-vault.mdx | 11 +- ...trello-board-with-supabase-and-angular.mdx | 4 +- ...-08-25-launch-week-5-hackathon-winners.mdx | 16 +- ...09-07-supabase-beta-update-august-2022.mdx | 47 ++- ...-09-08-choosing-a-postgres-primary-key.mdx | 157 +++++---- apps/www/_blog/2022-10-03-postgres-wasm.mdx | 2 +- ...05-supabase-beta-update-september-2022.mdx | 40 +-- ...-postgres-full-text-search-vs-the-rest.mdx | 10 +- ...hentication-and-authorization-with-rls.mdx | 44 +-- ...1-24-sql-or-nosql-both-with-postgresql.mdx | 256 +++++++------- ...parent-column-encryption-with-postgres.mdx | 10 +- .../2022-12-06-the-supabase-content-storm.mdx | 4 +- .../2022-12-09-launch-week-6-hackathon.mdx | 8 +- .../www/_blog/2022-12-14-mfa-auth-via-rls.mdx | 34 +- ...15-postgres-foreign-data-wrappers-rust.mdx | 11 +- ...2022-12-16-launch-week-6-community-day.mdx | 4 +- apps/www/_blog/2022-12-16-pg-graphql-v1.mdx | 4 +- ...2023-01-05-supabase-beta-december-2022.mdx | 2 +- ...2-03-openai-embeddings-postgres-vector.mdx | 6 +- ...-queries-with-postgis-in-ionic-angular.mdx | 212 ++++++------ ...-09-supabase-beta-update-february-2023.mdx | 4 +- ...023-04-07-designing-with-ai-midjourney.mdx | 75 ++-- .../2023-04-07-launch-week-7-hackathon.mdx | 14 +- ...-04-08-supabase-beta-update-march-2023.mdx | 15 +- apps/www/_blog/2023-04-14-dbdev.mdx | 6 +- ...023-04-21-whats-new-in-pg-graphql-v1-2.mdx | 14 +- ...-04-24-launch-week-7-hackathon-winners.mdx | 9 +- package-lock.json | 16 +- package.json | 4 +- 92 files changed, 1160 insertions(+), 1410 deletions(-) diff --git a/.prettierrc b/.prettierrc index b9bda117c38..c60d3ab91ef 100644 --- a/.prettierrc +++ b/.prettierrc @@ -5,5 +5,7 @@ "singleQuote": true, "printWidth": 100, "endOfLine": "lf", - "sqlKeywordCase": "lower" + "sqlKeywordCase": "lower", + "pluginSearchDirs": false, + "plugins": ["prettier-plugin-sql-cst"] } diff --git a/apps/docs/components/MDX/social_provider_settings_supabase.mdx b/apps/docs/components/MDX/social_provider_settings_supabase.mdx index 1cc3771e6f3..38e0d9e5bfe 100644 --- a/apps/docs/components/MDX/social_provider_settings_supabase.mdx +++ b/apps/docs/components/MDX/social_provider_settings_supabase.mdx @@ -3,4 +3,4 @@ - Click on [`Providers`](https://app.supabase.com/project/_/auth/providers) under the Configuration section - Click on **{props.provider}** from the accordion list to expand and turn **{props.provider} Enabled** to ON - Enter your **{props.provider} Client ID** and **{props.provider} Client Secret** saved in the previous step -- Click `Save` \ No newline at end of file +- Click `Save` diff --git a/apps/docs/docs/ref/javascript/v1/upgrade-guide.mdx b/apps/docs/docs/ref/javascript/v1/upgrade-guide.mdx index 01e843bbd42..d13e0311cae 100644 --- a/apps/docs/docs/ref/javascript/v1/upgrade-guide.mdx +++ b/apps/docs/docs/ref/javascript/v1/upgrade-guide.mdx @@ -89,7 +89,6 @@ The signIn() method has been deprecated in favor of more explicit method signatu defaultActiveId="1.0x" > -{/* prettier-ignore */} ```ts const { user, error } = await supabase .auth @@ -98,7 +97,6 @@ const { user, error } = await supabase -{/* prettier-ignore */} ```ts const { data: { user }, @@ -128,7 +126,6 @@ const { defaultActiveId="1.0x" > -{/* prettier-ignore */} ```ts const { error } = await supabase .auth @@ -137,7 +134,6 @@ const { error } = await supabase -{/* prettier-ignore */} ```ts const { error } = await supabase .auth @@ -165,7 +161,6 @@ const { error } = await supabase defaultActiveId="1.0x" > -{/* prettier-ignore */} ```ts const { error } = await supabase .auth @@ -174,7 +169,6 @@ const { error } = await supabase -{/* prettier-ignore */} ```ts const { error } = await supabase .auth @@ -201,7 +195,6 @@ const { error } = await supabase defaultActiveId="1.0x" > -{/* prettier-ignore */} ```ts const { error } = await supabase .auth @@ -210,7 +203,6 @@ const { error } = await supabase -{/* prettier-ignore */} ```ts const { error } = await supabase .auth @@ -238,7 +230,6 @@ const { error } = await supabase defaultActiveId="1.0x" > -{/* prettier-ignore */} ```ts const { error } = await supabase .auth @@ -248,16 +239,15 @@ const { error } = await supabase -{/* prettier-ignore */} ```ts const { data, error } = await supabase .auth .signInWithOtp({ phone }) - + // After receiving a SMS with a OTP. const { data, error } = await supabase -.auth -.verifyOtp({ phone, token }) + .auth + .verifyOtp({ phone, token }) ``` @@ -281,7 +271,6 @@ const { data, error } = await supabase defaultActiveId="1.0x" > -{/* prettier-ignore */} ```ts const { data, error } = await supabase .auth @@ -291,7 +280,6 @@ const { data, error } = await supabase -{/* prettier-ignore */} ```ts const { data, error } = await supabase .auth @@ -390,7 +378,6 @@ const { user } = session defaultActiveId="1.0x" > -{/* prettier-ignore */} ```ts const { user, error } = await supabase .auth @@ -435,7 +422,6 @@ const { user, error } = supabase.auth.setAuth(access_token) -{/* prettier-ignore */} ```ts const supabase = createClient( SUPABASE_URL, @@ -486,7 +472,6 @@ Previously, these methods return inserted/updated/deleted rows by default (which defaultActiveId="1.0x" > -{/* prettier-ignore */} ```ts const { data, error } = await supabase .from('my_table') @@ -495,7 +480,6 @@ const { data, error } = await supabase -{/* prettier-ignore */} ```ts const { data, error } = await supabase .from('my_table') @@ -524,7 +508,6 @@ const { data, error } = await supabase defaultActiveId="1.0x" > -{/* prettier-ignore */} ```ts const { data, error } = await supabase .from('my_table') @@ -534,7 +517,6 @@ const { data, error } = await supabase -{/* prettier-ignore */} ```ts const { data, error } = await supabase .from('my_table') @@ -564,7 +546,6 @@ const { data, error } = await supabase defaultActiveId="1.0x" > -{/* prettier-ignore */} ```ts const { data, error } = await supabase .from('my_table') @@ -573,7 +554,6 @@ const { data, error } = await supabase -{/* prettier-ignore */} ```ts const { data, error } = await supabase .from('my_table') @@ -602,7 +582,6 @@ const { data, error } = await supabase defaultActiveId="1.0x" > -{/* prettier-ignore */} ```ts const { data, error } = await supabase .from('my_table') @@ -612,7 +591,6 @@ const { data, error } = await supabase -{/* prettier-ignore */} ```ts const { data, error } = await supabase .from('my_table') diff --git a/apps/docs/docs/ref/self-hosting-auth/introduction.mdx b/apps/docs/docs/ref/self-hosting-auth/introduction.mdx index d33aee3de4f..0fe820ce9b3 100644 --- a/apps/docs/docs/ref/self-hosting-auth/introduction.mdx +++ b/apps/docs/docs/ref/self-hosting-auth/introduction.mdx @@ -14,9 +14,9 @@ hideTitle: true - The Supabase Auth Server (GoTrue) is a JSON Web Token (JWT)-based API for managing users and issuing access tokens. + The Supabase Auth Server (GoTrue) is a JSON Web Token (JWT)-based API for managing users and issuing access tokens. - GoTrue is an open-source API written in Golang, that acts as a self-standing API service for handling user registration and authentication for JAM projects. It's based on OAuth2 and JWT and handles user signup, authentication, and custom user data. + GoTrue is an open-source API written in Golang, that acts as a self-standing API service for handling user registration and authentication for JAM projects. It's based on OAuth2 and JWT and handles user signup, authentication, and custom user data. diff --git a/apps/docs/docs/ref/self-hosting-storage/introduction.mdx b/apps/docs/docs/ref/self-hosting-storage/introduction.mdx index 40fd27d4ce8..150820d09b2 100644 --- a/apps/docs/docs/ref/self-hosting-storage/introduction.mdx +++ b/apps/docs/docs/ref/self-hosting-storage/introduction.mdx @@ -14,12 +14,12 @@ hideTitle: true - 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, + } +} ```
@@ -740,27 +723,24 @@ export const GET: RequestHandler = async (event) => { ```ts title=src/routes/api/protected-route/+server.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 }) +} ```
- ## Migrate from 0.7.x to 0.8 [#migration-0-8] ### Set up the Supabase client [#migration-set-up-supabase-client-0-8] diff --git a/apps/docs/pages/guides/auth/quickstarts/react.mdx b/apps/docs/pages/guides/auth/quickstarts/react.mdx index 3ce980031f3..d173003dc1b 100644 --- a/apps/docs/pages/guides/auth/quickstarts/react.mdx +++ b/apps/docs/pages/guides/auth/quickstarts/react.mdx @@ -98,7 +98,7 @@ export const meta = { } = supabase.auth.onAuthStateChange((_event, session) => { setSession(session) }) - + return () => subscription.unsubscribe() }, []) diff --git a/apps/docs/pages/guides/auth/social-login/auth-github.mdx b/apps/docs/pages/guides/auth/social-login/auth-github.mdx index 5a3e76eed1d..31c5cf47b2a 100644 --- a/apps/docs/pages/guides/auth/social-login/auth-github.mdx +++ b/apps/docs/pages/guides/auth/social-login/auth-github.mdx @@ -36,7 +36,7 @@ Go to the [GitHub Developer Settings](https://github.com/settings/developers) pa -## Register a new OAuth application on Github. +## Register a new OAuth application on Github. - Navigate to `Settings`/`Developer settings`/`OAuth Apps` - Click `Register a new application`. If you've created an app before, click `New OAuth App` here. diff --git a/apps/docs/pages/guides/auth/sso/auth-sso-saml.mdx b/apps/docs/pages/guides/auth/sso/auth-sso-saml.mdx index 1923b2ed243..1e922686c78 100644 --- a/apps/docs/pages/guides/auth/sso/auth-sso-saml.mdx +++ b/apps/docs/pages/guides/auth/sso/auth-sso-saml.mdx @@ -105,17 +105,16 @@ A common use case with SSO is to use the UUID of the identity provider as the id For example, let's say you have a table like: ```sql -CREATE TABLE - organization_settings ( - -- the organization's unique ID - id UUID NOT NULL PRIMARY KEY, - -- the organization's SSO identity provider - sso_provider_id UUID UNIQUE, - -- name of the organization - name TEXT, - -- billing plan (paid, free, enterprise) - billing_plan TEXT - ); +create table organization_settings ( + -- the organization's unique ID + id uuid not null primary key, + -- the organization's SSO identity provider + sso_provider_id uuid unique, + -- name of the organization + name text, + -- billing plan (paid, free, enterprise) + billing_plan text +); ``` You can use the information present in the user's JWT to scope down which rows from this table the user can see, without doing any additional user management: diff --git a/apps/docs/pages/guides/database/extensions/pgsodium.mdx b/apps/docs/pages/guides/database/extensions/pgsodium.mdx index 1ac0c84b371..8e5f92ff5fe 100644 --- a/apps/docs/pages/guides/database/extensions/pgsodium.mdx +++ b/apps/docs/pages/guides/database/extensions/pgsodium.mdx @@ -12,13 +12,13 @@ extension which provides SQL access to algorithms. libsodium is a modern, easy-to-use software library for encryption, -decryption, signatures, password hashing, and more. It is a portable, +decryption, signatures, password hashing, and more. It is a portable, cross-compilable, installable, and packageable fork of the [NaCl](http://nacl.cr.yp.to/) library, with a compatible but extended API to improve usability even further. Its goal is to provide all of the core operations needed to build -higher-level cryptographic tools. Sodium is cross-platform and +higher-level cryptographic tools. Sodium is cross-platform and cross-language. It runs on many compilers and operating systems, including Windows (with MinGW or Visual Studio, x86 and x86_64), iOS, and Android. JavaScript and WebAssembly versions are also available @@ -33,12 +33,12 @@ pgsodium exposes the following libsodium APIs to SQL: - [Generating Random Data](https://github.com/michelp/pgsodium/#generating-random-data) - [Secret key cryptography](https://github.com/michelp/pgsodium/#secret-key-cryptography) - - [Authenticated encryption](https://github.com/michelp/pgsodium/#authenticated-encryption) - - [Authentication](https://github.com/michelp/pgsodium/#authentication) + - [Authenticated encryption](https://github.com/michelp/pgsodium/#authenticated-encryption) + - [Authentication](https://github.com/michelp/pgsodium/#authentication) - [Public key cryptography](https://github.com/michelp/pgsodium/#public-key-cryptography) - - [Authenticated encryption](https://github.com/michelp/pgsodium/#authenticated-encryption-1) - - [Public key signatures](https://github.com/michelp/pgsodium/#public-key-signatures) - - [Sealed boxes](https://github.com/michelp/pgsodium/#sealed-boxes) + - [Authenticated encryption](https://github.com/michelp/pgsodium/#authenticated-encryption-1) + - [Public key signatures](https://github.com/michelp/pgsodium/#public-key-signatures) + - [Sealed boxes](https://github.com/michelp/pgsodium/#sealed-boxes) - [Hashing](https://github.com/michelp/pgsodium/#hashing) - [Password hashing](https://github.com/michelp/pgsodium/#password-hashing) - [Key Derivation](https://github.com/michelp/pgsodium/#key-derivation) diff --git a/apps/docs/pages/guides/database/postgres/indexes.mdx b/apps/docs/pages/guides/database/postgres/indexes.mdx index 138143348de..60e7a3e2eeb 100644 --- a/apps/docs/pages/guides/database/postgres/indexes.mdx +++ b/apps/docs/pages/guides/database/postgres/indexes.mdx @@ -15,6 +15,7 @@ Even though indexes improve query performance, the Postgres query planner may no ## Create an index Let's take an example table: + ```sql create table persons ( id bigint generated by default as identity primary key, @@ -25,6 +26,7 @@ create table persons ( deceased boolean ); ``` + All the queries in this guide can be run using the [SQL Editor](https://app.supabase.com/project/_/sql) in the Supabase Dashboard, or via `psql` if you're [connecting directly to the database](/docs/guides/database/connecting-to-postgres#direct-connections). @@ -32,6 +34,7 @@ All the queries in this guide can be run using the [SQL Editor](https://app.supa We might want to frequently query users based on their age: + ```sql select name from persons where age = 32; ``` @@ -39,19 +42,22 @@ select name from persons where age = 32; Without an index, Postgres will scan every row in the table to find equality matches on age. You can verify this by doing an explain on the query: + ```sql explain select name from persons where age = 32; ``` Outputs: + ``` Seq Scan on persons (cost=0.00..22.75 rows=x width=y) Filter: (age = 32) ``` To add a simple B-Tree index you can run: + ```sql -create index idx_persons_age on persons(age); +create index idx_persons_age on persons (age); ``` @@ -73,7 +79,8 @@ You can see that in any large data set, traversing the index to locate a given v If you are frequently querying a subset of rows then it may be more efficient to build a partial index. In our example, perhaps we only want to match on `age` where `deceased is false`. We could build a partial index: ```sql -create index idx_living_persons_age ON persons(age) where deceased is false; +create index idx_living_persons_age on persons (age) +where deceased is false; ``` ## Ordering indexes @@ -81,14 +88,13 @@ create index idx_living_persons_age ON persons(age) where deceased is false; By default B-Tree indexes are sorted in ascending order, but sometimes you may want to provide a different ordering. Perhaps our application has a page featuring the top 10 oldest people. Here we would want to sort in descending order, and include `NULL` values last. For this we can use: ```sql -create index idx_persons_age_desc on persons(age desc nulls last); +create index idx_persons_age_desc on persons (age desc nulls last); ``` ## Reindexing After a while indexes can become stale and may need rebuilding. Postgres provides a `reindex` command for this, but due to Postgres locks being placed on the index during this process, you may want to make use of the `concurrent` keyword. - ```sql reindex index concurrently idx_persons_age; ``` @@ -103,4 +109,4 @@ Take note that `reindex` can be used inside a transaction, but `reindex [index/t export const Page = ({ children }) => -export default Page \ No newline at end of file +export default Page diff --git a/apps/docs/pages/guides/getting-started/tutorials/with-expo.mdx b/apps/docs/pages/guides/getting-started/tutorials/with-expo.mdx index aa420134d55..69d5b4f1b83 100644 --- a/apps/docs/pages/guides/getting-started/tutorials/with-expo.mdx +++ b/apps/docs/pages/guides/getting-started/tutorials/with-expo.mdx @@ -45,21 +45,20 @@ These variables will be exposed on the browser, and that's completely fine since [Row Level Security](/docs/guides/auth#row-level-security) enabled on our Database. ```ts title=lib/supabase.ts -import * as SecureStore from "expo-secure-store"; +import * as SecureStore from 'expo-secure-store' import { createClient } from '@supabase/supabase-js' - const ExpoSecureStoreAdapter = { getItem: (key: string) => { - return SecureStore.getItemAsync(key); + return SecureStore.getItemAsync(key) }, setItem: (key: string, value: string) => { - SecureStore.setItemAsync(key, value); + SecureStore.setItemAsync(key, value) }, removeItem: (key: string) => { - SecureStore.deleteItemAsync(key); + SecureStore.deleteItemAsync(key) }, -}; +} const supabaseUrl = YOUR_REACT_NATIVE_SUPABASE_URL const supabaseAnonKey = YOUR_REACT_NATIVE_SUPABASE_ANON_KEY diff --git a/apps/docs/pages/guides/getting-started/tutorials/with-nextjs.mdx b/apps/docs/pages/guides/getting-started/tutorials/with-nextjs.mdx index 980ca00eef6..18b670d813f 100644 --- a/apps/docs/pages/guides/getting-started/tutorials/with-nextjs.mdx +++ b/apps/docs/pages/guides/getting-started/tutorials/with-nextjs.mdx @@ -126,7 +126,7 @@ export default MyApp Wrap your `pages/_app.tsx` component with the `SessionContextProvider` component: ```jsx lines=2,8 title=pages/_app.tsx -import '../styles/globals.css'; +import '../styles/globals.css' import { useState } from 'react' import { createBrowserSupabaseClient } from '@supabase/auth-helpers-nextjs' import { SessionContextProvider, Session } from '@supabase/auth-helpers-react' diff --git a/apps/docs/pages/guides/getting-started/tutorials/with-solidjs.mdx b/apps/docs/pages/guides/getting-started/tutorials/with-solidjs.mdx index c56047307f9..8c9188408cb 100644 --- a/apps/docs/pages/guides/getting-started/tutorials/with-solidjs.mdx +++ b/apps/docs/pages/guides/getting-started/tutorials/with-solidjs.mdx @@ -122,13 +122,13 @@ After a user is signed in we can allow them to edit their profile details and ma Let's create a new component for that called `Account.tsx`. -```jsx title=src/Account.tsx +```tsx title=src/Account.tsx import { AuthSession } from '@supabase/supabase-js' import { Component, createEffect, createSignal } from 'solid-js' import { supabase } from './supabaseClient' interface Props { - session: AuthSession; + session: AuthSession } const Account: Component = ({ session }) => { diff --git a/apps/docs/pages/guides/getting-started/tutorials/with-sveltekit.mdx b/apps/docs/pages/guides/getting-started/tutorials/with-sveltekit.mdx index 3d52b20f8d1..98633bc1d9d 100644 --- a/apps/docs/pages/guides/getting-started/tutorials/with-sveltekit.mdx +++ b/apps/docs/pages/guides/getting-started/tutorials/with-sveltekit.mdx @@ -63,29 +63,26 @@ Add the code below to your `src/hooks.server.ts` to initialize the client on the ```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 convenience helper so we can just call await getSession() instead const { data: { session } } = await supabase.auth.getSession() */ 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, { /** @@ -94,10 +91,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' + }, + }) +} ``` If you are using TypeScript the compiler might complain about `event.locals.supabase` and `event.locals.getSession`, this can be fixed by updating your `src/app.d.ts` with the content below: @@ -105,16 +102,16 @@ If you are using TypeScript the compiler might complain about `event.locals.supa ```ts title=src/app.d.ts // src/app.d.ts -import { SupabaseClient, Session } from '@supabase/supabase-js'; +import { SupabaseClient, Session } from '@supabase/supabase-js' 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 {} @@ -126,13 +123,13 @@ Create a new `src/routes/+layout.server.ts` file to handle the session on the se ```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(), + } +} ``` > Start your dev server (`npm run dev`) in order to generate the `./$types` files we are referencing in our project. @@ -141,30 +138,27 @@ Create a new `src/routes/+layout.ts` file to handle the session and the supabase ```ts title=src/routes/+layout.ts // src/routes/+layout.ts -import { invalidate } from '$app/navigation'; -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 { invalidate } from '$app/navigation' +import { PUBLIC_SUPABASE_ANON_KEY, PUBLIC_SUPABASE_URL } from '$env/static/public' +import { createSupabaseLoadClient } from '@supabase/auth-helpers-sveltekit' +import type { LayoutLoad } from './$types' 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 } +} ``` Update your `src/routes/+layout.svelte`: @@ -244,25 +238,26 @@ Add the `Auth` component to your home page Create a `src/routes/+page.server.ts` file that will return our website url to be used in our `redirectTo` above. -> This is necessary because the current Supabase auth flow uses implicit grant which returns the tokens as part of the url fragment (#). -The redirect to a non server protected page will make sure that the client captures the url fragment as we cannot read these on the server -and send it over to the server. This all happens behind the scenes and isn't something you will need to do manually. +> This is necessary because the current Supabase auth flow uses implicit grant which returns the tokens as part of the url fragment (#). + +> The redirect to a non server protected page will make sure that the client captures the url fragment as we cannot read these on the server +> and send it over to the server. This all happens behind the scenes and isn't something you will need to do manually. ```ts // src/routes/+page.server.ts -import { redirect } from '@sveltejs/kit'; -import type { PageServerLoad } from './$types'; +import { redirect } from '@sveltejs/kit' +import type { PageServerLoad } from './$types' export const load: PageServerLoad = async ({ url, locals: { getSession } }) => { - const session = await getSession(); + const session = await getSession() - // if the user is already logged in return them to the account page - if (session) { - throw redirect(303, '/account'); - } + // if the user is already logged in return them to the account page + if (session) { + throw redirect(303, '/account') + } - return { url: url.origin }; -}; + return { url: url.origin } +} ``` ### Loading page @@ -378,68 +373,68 @@ Now create the associated `src/routes/account/+page.server.ts` file that will ha and handle all our form actions through the `actions` object. ```ts -import { fail, redirect } from '@sveltejs/kit'; -import type { Actions, PageServerLoad } from './$types'; +import { fail, redirect } from '@sveltejs/kit' +import type { Actions, PageServerLoad } from './$types' export const load = (async ({ locals: { supabase, getSession } }) => { - const session = await getSession(); + const session = await getSession() - if (!session) { - throw redirect(303, '/'); - } + if (!session) { + throw redirect(303, '/') + } - const { data: profile } = await supabase - .from('profiles') - .select(`username, full_name, website, avatar_url`) - .eq('id', session.user.id) - .single(); + const { data: profile } = await supabase + .from('profiles') + .select(`username, full_name, website, avatar_url`) + .eq('id', session.user.id) + .single() - return { session, profile }; -}) satisfies PageServerLoad; + return { session, profile } +}) satisfies PageServerLoad export const actions = { - update: async ({ request, locals: { supabase, getSession } }) => { - const formData = await request.formData(); - const fullName = formData.get('fullName') as string; - const username = formData.get('username') as string; - const website = formData.get('website') as string; - const avatarUrl = formData.get('avatarUrl') as string; + update: async ({ request, locals: { supabase, getSession } }) => { + const formData = await request.formData() + const fullName = formData.get('fullName') as string + const username = formData.get('username') as string + const website = formData.get('website') as string + const avatarUrl = formData.get('avatarUrl') as string - const session = await getSession(); + const session = await getSession() - const { error } = await supabase.from('profiles').upsert({ - id: session?.user.id, - full_name: fullName, - username, - website, - avatar_url: avatarUrl, - updated_at: new Date() - }); + const { error } = await supabase.from('profiles').upsert({ + id: session?.user.id, + full_name: fullName, + username, + website, + avatar_url: avatarUrl, + updated_at: new Date(), + }) - if (error) { - return fail(500, { - fullName, - username, - website, - avatarUrl - }); - } + if (error) { + return fail(500, { + fullName, + username, + website, + avatarUrl, + }) + } - return { - fullName, - username, - website, - avatarUrl - }; - }, - signout: async ({ locals: { supabase, getSession } }) => { - const session = await getSession(); - if (session) { - await supabase.auth.signOut(); - throw redirect(303, '/'); - } - } -} satisfies Actions; + return { + fullName, + username, + website, + avatarUrl, + } + }, + signout: async ({ locals: { supabase, getSession } }) => { + const session = await getSession() + if (session) { + await supabase.auth.signOut() + throw redirect(303, '/') + } + }, +} satisfies Actions ``` ### Launch! diff --git a/apps/docs/pages/guides/getting-started/tutorials/with-vue-3.mdx b/apps/docs/pages/guides/getting-started/tutorials/with-vue-3.mdx index 98b8bcce015..0263b65ea7c 100644 --- a/apps/docs/pages/guides/getting-started/tutorials/with-vue-3.mdx +++ b/apps/docs/pages/guides/getting-started/tutorials/with-vue-3.mdx @@ -65,7 +65,7 @@ Optionally, update [src/style.css](https://raw.githubusercontent.com/supabase/su ### Set up a Login component -Set up an `src/components/Auth.vue` component to manage logins and sign ups. We'll use Magic Links, so users can sign in with their email without using passwords. +Set up an `src/components/Auth.vue` component to manage logins and sign ups. We'll use Magic Links, so users can sign in with their email without using passwords. ```vue title=/src/components/Auth.vue