- This reference documents every object and method available in Supabase's Flutter
- library, [supabase-flutter](https://pub.dev/packages/supabase_flutter). You can
- use supabase-flutter 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 [supabase](https://pub.dev/packages/supabase) package for non-Flutter projects.
+
+This reference documents every object and method available in Supabase's Flutter
+library, [supabase-flutter](https://pub.dev/packages/supabase_flutter). You can
+use supabase-flutter 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-Flutter projects.
+
+
+
+ You're viewing the docs for an older version of the `supabase-flutter` library. Learn how to
+ [upgrade to the latest version](/docs/reference/dart/v0/upgrade-guide).
+
+
+This reference documents every object and method available in Supabase's Flutter library, [supabase-flutter](https://pub.dev/packages/supabase_flutter).
+You can use supabase-flutter 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-Flutter projects.
+
+
diff --git a/apps/docs/docs/reference/dart/upgrade-guide.mdx b/apps/docs/docs/ref/dart/v0/upgrade-guide.mdx
similarity index 68%
rename from apps/docs/docs/reference/dart/upgrade-guide.mdx
rename to apps/docs/docs/ref/dart/v0/upgrade-guide.mdx
index 707cdd06129..6da7b0c0fe5 100644
--- a/apps/docs/docs/reference/dart/upgrade-guide.mdx
+++ b/apps/docs/docs/ref/dart/v0/upgrade-guide.mdx
@@ -4,23 +4,35 @@ title: Upgrade to supabase-flutter v1
description: 'Learn how to upgrade to supabase-flutter v1.'
---
-import Tabs from '@theme/Tabs'
-import TabItem from '@theme/TabItem'
-
-supabase-flutter focuses on improving the developer experience and making it easier to use. This guide will help you upgrade from supabase-flutter v0 to v1.
+supabase-flutter focuses on improving the developer experience and making it easier to use. This guide demonstrates how to upgrade from supabase-flutter v0 to v1.
## Upgrade the client library
+
+
+
Update the package in your pubspec.yaml file.
+
+
+
```yaml
supabase_flutter: ^1.0.0
```
+
+
+
## Error handling
+
+
+
The way supabase-flutter throws error has changed in v1. In v0, errors were returned as a response. In v1, errors are thrown as exceptions. This makes it more intuitive as a Flutter developer to handle errors.
+
+
+
-## Auth classes / methods
+
+
+
+## Auth classes and methods
### Usage of `SupabaseAuthState` and `SupabaseAuthRequiredState` classes
-In v0, `SupabaseAuthState` and `SupabaseAuthRequiredState` were required to handle automatic token refresh and to listen to auth state change. In v1, `SupabaseAuthState` and `SupabaseAuthRequiredState` are deprecated, and token refresh will happen automatically just by initializing Supabase. [`onAuthStateChange`](/docs/reference/dart/upgrade-guide#listening-to-auth-state-change) can be used to action on auth state change.
+
+
+
+In v0, `SupabaseAuthState` and `SupabaseAuthRequiredState` were required to handle automatic token refresh and to listen to auth state change. In v1, `SupabaseAuthState` and `SupabaseAuthRequiredState` are deprecated, and token refresh will happen automatically just by initializing Supabase. [`onAuthStateChange`](#listening-to-auth-state-change) can be used to action on auth state change.
+
+
+
+
+
+
### Listening to auth state change
+
+
+
`onAuthStateChange` now returns a `Stream`.
+
+
+
+
+
+
### Sign in with email and password
-The signIn() method has been deprecated in favor of more explicit method signatures to help with type hinting. Previously it was difficult for developers to know what they were missing (e.g., a lot of developers didn't realize they could use passwordless magic links).
+
+
+
+`signIn()` has been deprecated in favor of more explicit method signatures to help with type hinting. Previously it was difficult for developers to know what they were missing (e.g., a lot of developers didn't realize they could use passwordless magic links).
+
+
+
+
+
+
+
+
+
### Sign in with magic link
+
+
+
+
+
+
+
+
+
### Sign in with a third-party OAuth provider
+
+
+
+
+
+
+
+
+
### Sign in with phone
+
+
+
+
+
+
+
+
+
### Sign in with phone using OTP
+
+
+
+
+
+
+
+
+
### Reset password for email
+
+
+
+
+
+
+
+
+
### Get the user's current session
+
+
+
+
+
+
+
+
+
### Get the logged-in user
+
+
+
+
+
+
+
+
+
### Update user data for a logged-in user
+
+
+
+
+
+
## Data methods
-`.insert()` / `.upsert()` / `.update()` / `.delete()` don't return rows by default.
+`.insert()` / `.upsert()` / `.update()` / `.delete()` no longer return rows by default. Previously, these methods return inserted/updated/deleted rows by default (which caused [some confusion](https://github.com/supabase/supabase/discussions/1548)), and you can opt to not return it by specifying `returning: 'minimal'`. Now the default behavior is to not return rows. To return inserted/updated/deleted rows, add a `.select()` call at the end.
-Previously, these methods return inserted/updated/deleted rows by default (which caused [some confusion](https://github.com/supabase/supabase/discussions/1548)), and you can opt to not return it by specifying `returning: 'minimal'`. Now the default behavior is to not return rows. To return inserted/updated/deleted rows, add a `.select()` call at the end.
+Also, calling `.execute()` at the end of the query was a requirement in v0, but deprecated in v1.
-Also, calling `.execute()` at the end of the query was a requirement in v0, but in v1 `.execute` is deperecated.
+
+
### Insert without returning inserted data
+
+
+
+
+
+
+
+
+
### Insert with returning inserted data
+
+
+
+
+
+
## Realtime methods
+
+
+
### Stream
`.stream()` no longer needs the `.execute()` at the end. Also, filtering by `eq` is a lot easier now. `primaryKey` is now a named parameter to make it more obvious what to pass.
+
+
+
+
+
+
+
+
+
### Subscribe
+
+
+
+
+
+
+
+
+
### Unsubscribe
+
+
+
+
+
+
diff --git a/apps/docs/docs/ref/javascript/v1/introduction.mdx b/apps/docs/docs/ref/javascript/v1/introduction.mdx
index 3e1af1ff9dd..a62134bdd69 100644
--- a/apps/docs/docs/ref/javascript/v1/introduction.mdx
+++ b/apps/docs/docs/ref/javascript/v1/introduction.mdx
@@ -13,8 +13,15 @@ hideTitle: true
- This reference documents every object and method available in Supabase's isomorphic JavaScript
- library, supabase-js. You can use supabase-js to interact with your Postgres database, listen to
- database changes, invoke Deno Edge Functions, build login and user management functionality, and
- manage large files.
+
+
+ You're viewing the docs for an older version of the `supabase-js` library. Learn how to [upgrade
+ to the latest version](/docs/reference/javascript/v1/upgrade-guide).
+
+
+This reference documents every object and method available in Supabase's isomorphic JavaScript
+library, supabase-js. You can use supabase-js to interact with your Postgres database, listen to
+database changes, invoke Deno Edge Functions, build login and user management functionality, and
+manage large files.
+
diff --git a/apps/docs/docs/ref/javascript/upgrade-guide.mdx b/apps/docs/docs/ref/javascript/v1/upgrade-guide.mdx
similarity index 100%
rename from apps/docs/docs/ref/javascript/upgrade-guide.mdx
rename to apps/docs/docs/ref/javascript/v1/upgrade-guide.mdx
diff --git a/apps/docs/docs/reference/javascript/upgrade-guide.mdx b/apps/docs/docs/reference/javascript/upgrade-guide.mdx
deleted file mode 100644
index 282d66d4966..00000000000
--- a/apps/docs/docs/reference/javascript/upgrade-guide.mdx
+++ /dev/null
@@ -1,439 +0,0 @@
----
-id: upgrade-guide
-title: Upgrade to supabase-js v2
-description: 'Learn how to upgrade to supabase-js v2.'
----
-
-import Tabs from '@theme/Tabs'
-import TabItem from '@theme/TabItem'
-
-supabase-js v2 focuses on "quality-of-life" improvements for developers and addresses some of the largest pain points in v1. v2 includes type support, a rebuilt Auth library with async methods, improved errors, and more.
-
-No new features will be added to supabase-js v1 , but we'll continuing merging security fixes to v1, with maintenance patches for the next 3 months.
-
-## Upgrade the client library
-
-```sh
-npm install @supabase/supabase-js@2
-```
-
-_Optionally_ if you are using custom configuration with `createClient` then follow below:
-
-
-
-
-```ts title=src/supabaseClient.ts
-const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
- schema: 'custom',
- persistSession: false,
-})
-```
-
-
-
-
-```ts title=src/supabaseClient.ts
-const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
- db: {
- schema: 'custom',
- },
- auth: {
- persistSession: true,
- },
-})
-```
-
-
-
-
-Read more about the [constructor options](/docs/reference/javascript/release-notes#explicit-constructor-options).
-
-### Auth methods
-
-The signIn() method has been deprecated in favor of more explicit method signatures to help with type hinting. Previously it was difficult for developers to know what they were missing (e.g., a lot of developers didn't realize they could use passwordless magic links).
-
-#### Sign in with email and password
-
-
-
-
-```ts
-const { user, error } = await supabase.auth.signIn({ email, password })
-```
-
-
-
-
-```ts
-const {
- data: { user },
- error,
-} = await supabase.auth.signInWithPassword({ email, password })
-```
-
-
-
-
-#### Sign in with magic link
-
-
-
-
-```ts
-const { error } = await supabase.auth.signIn({ email })
-```
-
-
-
-
-```ts
-const { error } = await supabase.auth.signInWithOtp({ email })
-```
-
-
-
-
-#### Sign in with a third-party provider
-
-
-
-
-```ts
-const { error } = await supabase.auth.signIn({ provider })
-```
-
-
-
-
-```ts
-const { error } = await supabase.auth.signInWithOAuth({ provider })
-```
-
-
-
-
-#### Sign in with phone
-
-
-
-
-```ts
-const { error } = await supabase.auth.signIn({ phone, password })
-```
-
-
-
-
-```ts
-const { error } = await supabase.auth.signInWithPassword({ phone, password })
-```
-
-
-
-
-#### Sign in with phone using OTP
-
-
-
-
-```ts
-const { error } = await supabase.auth.api.sendMobileOTP(phone)
-```
-
-
-
-
-```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 })
-```
-
-
-
-
-#### Reset password for email
-
-
-
-
-```ts
-const { data, error } = await supabase.auth.api.resetPasswordForEmail(email)
-```
-
-
-
-
-```ts
-const { data, error } = await supabase.auth.resetPasswordForEmail(email)
-```
-
-
-
-
-#### Get the user's current session
-
-
-
-
-```ts
-const session = supabase.auth.session()
-```
-
-
-
-
-```ts
-const {
- data: { session },
-} = await supabase.auth.getSession()
-```
-
-
-
-
-#### Get the logged-in user
-
-
-
-
-```ts
-const user = supabase.auth.user()
-```
-
-
-
-
-```ts
-const {
- data: { session },
-} = await supabase.auth.getSession()
-const { user } = session
-```
-
-
-
-
-#### Update user data for a logged-in user
-
-
-
-
-```ts
-const { user, error } = await supabase.auth.update({ attributes })
-```
-
-
-
-
-```ts
-const {
- data: { user },
- error,
-} = await supabase.auth.updateUser({ attributes })
-```
-
-
-
-
-#### Use a custom `access_token` JWT with Supabase
-
-
-
-
-```ts
-const { user, error } = supabase.auth.setAuth(access_token)
-```
-
-
-
-
-```ts
-const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
- global: {
- headers: {
- Authorization: `Bearer ${access_token}`,
- },
- },
-})
-```
-
-
-
-
-#### Cookie methods
-
-The cookie-related methods like `setAuthCookie` and `getUserByCookie` have been removed.
-
-For Next.js you can use the [Auth Helpers](https://supabase.com/docs/guides/auth/auth-helpers/nextjs) to help you manage cookies.
-If you can't use the Auth Helpers, you can use [server-side rendering](https://supabase.com/docs/guides/auth/server-side-rendering).
-
-Some the [PR](https://github.com/supabase/gotrue-js/pull/340) for additional background information.
-
-### Data methods
-
-`.insert()` / `.upsert()` / `.update()` / `.delete()` don't return rows by default: [PR](https://github.com/supabase/postgrest-js/pull/276).
-
-Previously, these methods return inserted/updated/deleted rows by default (which caused [some confusion](https://github.com/supabase/supabase/discussions/1548)), and you can opt to not return it by specifying `returning: 'minimal'`. Now the default behavior is to not return rows. To return inserted/updated/deleted rows, add a `.select()` call at the end.
-
-#### Insert and return data
-
-
-
-
-```ts
-const { data, error } = await supabase.auth.insert({ new_data })
-```
-
-
-
-
-```ts
-const { data, error } = await supabase.auth.insert({ new_data }).select()
-```
-
-
-
-
-#### Update and return data
-
-
-
-
-```ts
-const { data, error } = await supabase.auth.update({ new_data }).eq('id', id)
-```
-
-
-
-
-```ts
-const { data, error } = await supabase.auth.update({ new_data }).eq('id', id).select()
-```
-
-
-
-
-### Realtime methods
-
-#### Subscribe
-
-
-
-
-```ts
-const userListener = supabase
- .from('users')
- .on('*', (payload) => handleAllEventsPayload(payload.new))
- .subscribe()
-```
-
-
-
-
-```ts
-const userListener = supabase
- .channel('public:user')
- .on('postgres_changes', { event: '*', schema: 'public', table: 'user' }, (payload) =>
- handleAllEventsPayload()
- )
- .subscribe()
-```
-
-
-
-
-#### Unsubscribe
-
-
-
-
-```ts
-userListener.unsubscribe()
-```
-
-
-
-
-```ts
-supabase.removeChannel(userListener)
-```
-
-
-
diff --git a/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdx b/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdx
index 76e169c2271..9985e50fb92 100644
--- a/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdx
+++ b/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdx
@@ -584,7 +584,7 @@ export async function middleware(req: NextRequest) {
}
export const config = {
- matcher: '/middleware-protected',
+ matcher: '/middleware-protected/:path*',
}
```
@@ -782,7 +782,7 @@ export const config = {
### Migrating to v0.4.X and supabase-js v2
-With the update to `supabase-js` v2 the `auth` API routes are no longer required, therefore you can go ahead and delete your `auth` directory under the `/pages/api/` directory. Please refer to the [v2 migration guide](/docs/reference/javascript/upgrade-guide) for the full set of changes within supabase-js.
+With the update to `supabase-js` v2 the `auth` API routes are no longer required, therefore you can go ahead and delete your `auth` directory under the `/pages/api/` directory. Please refer to the [v2 migration guide](/docs/reference/javascript/v1/upgrade-guide) for the full set of changes within supabase-js.
The `/api/auth/logout` API route has been removed, please use the `signout` method instead:
diff --git a/apps/docs/pages/guides/auth/social-login/auth-azure.mdx b/apps/docs/pages/guides/auth/social-login/auth-azure.mdx
index d75a365b1d5..57f398456b0 100644
--- a/apps/docs/pages/guides/auth/social-login/auth-azure.mdx
+++ b/apps/docs/pages/guides/auth/social-login/auth-azure.mdx
@@ -74,14 +74,12 @@ When your user signs in, call [signInWithOAuth()](/docs/reference/javascript/aut
```js
async function signInWithAzure() {
- const { data, error } = await supabase.auth.signInWithOAuth(
- {
- provider: 'azure',
- },
- {
+ const { data, error } = await supabase.auth.signInWithOAuth({
+ provider: 'azure',
+ options: {
scopes: 'email',
- }
- )
+ },
+ })
}
```
diff --git a/apps/docs/pages/guides/database/extensions/pgcron.mdx b/apps/docs/pages/guides/database/extensions/pgcron.mdx
index 57a704e444a..1062db0fd32 100644
--- a/apps/docs/pages/guides/database/extensions/pgcron.mdx
+++ b/apps/docs/pages/guides/database/extensions/pgcron.mdx
@@ -63,6 +63,8 @@ The schedule uses the standard cron syntax, in which \* means "run every time pe
* * * * *
```
+You can use [crontab.guru](https://crontab.guru/) to help validate your cron schedules.
+
## Examples
### Delete data every week
@@ -71,8 +73,8 @@ Delete old data on Saturday at 3:30am (GMT):
```sql
select cron.schedule (
- 'webhook-every-minute', -- name of the cron job
- '* * * * *', -- every minute
+ 'saturday-cleanup', -- name of the cron job
+ '30 3 * * 6', -- Saturday at 3:30am (GMT)
$$ delete from events where event_time < now() - interval '1 week' $$
);
```
@@ -85,6 +87,26 @@ Vacuum every day at 3:00am (GMT)
SELECT cron.schedule('nightly-vacuum', '0 3 * * *', 'VACUUM');
```
+### Invoke Supabase Edge Function every minute
+
+Make a POST request to a Supabase Edge Function every minute. Note: this requires the [`pg_net` extension](/docs/guides/database/extensions/pgnet) to be enabled.
+
+```sql
+select
+ cron.schedule(
+ 'invoke-function-every-minute',
+ '* * * * *', -- every minute
+ $$
+ select
+ net.http_post(
+ url:='https://project-ref.functions.supabase.co/function-name',
+ headers:='{"Content-Type": "application/json", "Authorization": "Bearer YOUR_ANON_KEY"}'::jsonb,
+ body:=concat('{"time": "', now(), '"}')::jsonb
+ ) as request_id;
+ $$
+ );
+```
+
### Unschedule a job
Unschedules a job called `'nightly-vacuum'`
diff --git a/apps/docs/pages/guides/database/extensions/pgnet.mdx b/apps/docs/pages/guides/database/extensions/pgnet.mdx
index 29283ab4430..18c51a8dd2a 100644
--- a/apps/docs/pages/guides/database/extensions/pgnet.mdx
+++ b/apps/docs/pages/guides/database/extensions/pgnet.mdx
@@ -53,11 +53,11 @@ Procedural languages are automatically installed within `pg_catalog`, so you don
-## `http_get` [#http_get]
+## `http_get`
Creates an HTTP GET request returning the request's ID. HTTP requests are not started until the transaction is committed.
-### Signature
+### Signature [#get-signature]
@@ -86,7 +86,7 @@ net.http_get(
language plpgsql
```
-### Usage
+### Usage [#get-usage]
```sql
select net.http_get('https://news.ycombinator.com') as request_id;
@@ -98,13 +98,13 @@ request_id
After triggering `http_get`, use [`http_get_result`](#http_get_result) to get the result of the request.
-## `http_post` [#http_post]
+## `http_post`
Creates an HTTP POST request with a JSON body, returning the request's ID. HTTP requests are not started until the transaction is committed.
The body's character set encoding matches the database's `server_encoding` setting.
-### Signature
+### Signature [#post-signature]
@@ -134,7 +134,7 @@ net.http_post(
language plpgsql
```
-### Usage
+### Usage [#post-usage]
```sql
select
@@ -150,6 +150,21 @@ request_id
After triggering `http_post`, use [`http_get_result`](#http_get_result) to get the result of the request.
+## Examples
+
+### Invoke a Supabase Edge Function
+
+Make a POST request to a Supabase Edge Function with auth header and JSON body payload:
+
+```sql
+select
+ net.http_post(
+ url:='https://project-ref.functions.supabase.co/function-name',
+ headers:='{"Content-Type": "application/json", "Authorization": "Bearer YOUR_ANON_KEY"}'::jsonb,
+ body:='{"name": "pg_net"}'::jsonb
+ ) as request_id;
+```
+
## Resources
- Source code: [github.com/supabase/pg_net](https://github.com/supabase/pg_net/)
diff --git a/apps/docs/pages/guides/functions/best-practices.mdx b/apps/docs/pages/guides/functions/best-practices.mdx
deleted file mode 100644
index b670cd73a05..00000000000
--- a/apps/docs/pages/guides/functions/best-practices.mdx
+++ /dev/null
@@ -1,64 +0,0 @@
-import Layout from '~/layouts/DefaultGuideLayout'
-
-export const meta = {
- id: 'functions-best-practices',
- title: 'Edge Functions Best Practices',
- description: 'Globally distributed TypeScript functions.',
-}
-
-## Database Functions vs Edge Functions
-
-For data-intensive operations we recommend using [Database Functions](/docs/guides/database/functions), which are executed within your database
-and can be called remotely using the [REST and GraphQL API](/docs/guides/api).
-
-For use-cases which require low-latency we recommend [Edge Functions](/docs/guides/functions), which are globally-distributed and can be written in TypeScript.
-
-## Organizing your Edge Functions
-
-We recommend developing “fat functions”. This means that you should develop few large functions, rather than many small functions. One common pattern when developing Functions is that you need to share code between two or more Functions. To do this, you can store any shared code in a folder prefixed with an underscore (`_`). We recommend this folder structure:
-
-```bash
-└── supabase
- ├── functions
- │ ├── _shared
- │ | ├── supabaseAdmin.ts # Supabase client with SERVICE_ROLE key
- │ │ └── supabaseClient.ts # Supabase client with ANON key
- │ ├── function-one # use hyphens to name functions
- │ │ └── index.ts
- │ └── function-two
- │ └── index.ts
- ├── migrations
- └── config.toml
-```
-
-## Naming Edge Functions
-
-We recommend using hyphens to name functions because hyphens are the most URL-friendly of all the naming conventions (snake_case, camelCase, PascalCase).
-
-## CORS (Cross-Origin Resource Sharing)
-
-We recommend adding a check to handle [CORS Preflight](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request) requests in your edge function to be able to invoke the function from browsers.
-
-See the [example on GitHub](https://github.com/supabase/supabase/blob/master/examples/edge-functions/supabase/functions/browser-with-cors/index.ts).
-
-```ts
-export const corsHeaders = {
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey',
-}
-
-serve(async (req) => {
- if (req.method === 'OPTIONS') {
- return new Response('ok', { headers: corsHeaders })
- }
- ...
-})
-```
-
-## Using HTTP Methods
-
-Edge Functions supports `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, and `OPTIONS`. A function can be designed to perform different actions based on a request's HTTP method. See the [example on building a RESTful service](https://github.com/supabase/supabase/tree/master/examples/edge-functions/supabase/functions/restful-tasks) to learn how to handle different HTTP methods in your function.
-
-export const Page = ({ children }) =>
-
-export default Page
diff --git a/apps/docs/pages/guides/functions/cicd-workflow.mdx b/apps/docs/pages/guides/functions/cicd-workflow.mdx
index e902f140370..fd7826ddf0e 100644
--- a/apps/docs/pages/guides/functions/cicd-workflow.mdx
+++ b/apps/docs/pages/guides/functions/cicd-workflow.mdx
@@ -35,6 +35,15 @@ jobs:
- run: supabase functions deploy your-function-name --project-ref $PROJECT_ID
```
+
+
+
+
See the [example on GitHub](https://github.com/supabase/supabase/blob/master/examples/edge-functions/.github/workflows/deploy.yaml).
export const Page = ({ children }) =>
diff --git a/apps/docs/pages/guides/functions/cors.mdx b/apps/docs/pages/guides/functions/cors.mdx
new file mode 100644
index 00000000000..14f1a1208d9
--- /dev/null
+++ b/apps/docs/pages/guides/functions/cors.mdx
@@ -0,0 +1,59 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'functions-cors',
+ title: 'CORS (Cross-Origin Resource Sharing)',
+ description: 'Add CORS headers to invoke functions from the browser.',
+}
+
+To invoke the functions from the browser, you need to handle [CORS Preflight](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request) requests.
+
+See the [example on GitHub](https://github.com/supabase/supabase/blob/master/examples/edge-functions/supabase/functions/browser-with-cors/index.ts).
+
+### Recommended setup
+
+We recommend adding a `corst.ts` file within a [`_shared` folder](/docs/guides/functions/quickstart#organizing-your-edge-functions) which makes it easy to reuse the CORS headers across functions:
+
+```ts cors.ts
+export const corsHeaders = {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
+}
+```
+
+You can then import and use the CORS headers within your functions:
+
+```ts index.ts
+import { serve } from 'https://deno.land/std@0.131.0/http/server.ts'
+import { corsHeaders } from '../_shared/cors.ts'
+
+console.log(`Function "browser-with-cors" up and running!`)
+
+serve(async (req) => {
+ // This is needed if you're planning to invoke your function from a browser.
+ if (req.method === 'OPTIONS') {
+ return new Response('ok', { headers: corsHeaders })
+ }
+
+ try {
+ const { name } = await req.json()
+ const data = {
+ message: `Hello ${name}!`,
+ }
+
+ return new Response(JSON.stringify(data), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 200,
+ })
+ } catch (error) {
+ return new Response(JSON.stringify({ error: error.message }), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 400,
+ })
+ }
+})
+```
+
+export const Page = ({ children }) =>
+
+export default Page
diff --git a/apps/docs/pages/guides/functions/debugging.mdx b/apps/docs/pages/guides/functions/debugging.mdx
new file mode 100644
index 00000000000..62c93035b2a
--- /dev/null
+++ b/apps/docs/pages/guides/functions/debugging.mdx
@@ -0,0 +1,20 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'functions-debugging',
+ title: 'Debugging Functions',
+ description: 'Debug functions in production.',
+}
+
+You can debug your deployed Edge Functions using the ["Functions" section](https://app.supabase.com/project/_/functions) of the Dashboard. There are two debugging tools available:
+
+- Invocations: shows the Request and Response for each execution.
+- Logs: shows any platform events, including deployments and errors.
+
+
+
+When [developing locally](/docs/guides/functions/local-development) you will see error messages and console log statements printed to your local terminal window.
+
+export const Page = ({ children }) =>
+
+export default Page
diff --git a/apps/docs/pages/guides/functions/examples/cloudflare-turnstile.mdx b/apps/docs/pages/guides/functions/examples/cloudflare-turnstile.mdx
new file mode 100644
index 00000000000..560b3d9e454
--- /dev/null
+++ b/apps/docs/pages/guides/functions/examples/cloudflare-turnstile.mdx
@@ -0,0 +1,96 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'examples-cloudflare-turnstile',
+ title: 'Cloudflare Turnstile',
+ description: 'Protecting Forms with Cloudflare Turnstile.',
+}
+
+
+
+
+
+[Clouflare Turnstile](https://www.cloudflare.com/products/turnstile/) is a friendly, free CAPTCHA replacement, and it works seamlessly with Supabase Edge Functions to protect your forms. [View on GitHub](https://github.com/supabase/supabase/tree/master/examples/edge-functions/supabase/functions/cloudflare-turnstile).
+
+## Setup
+
+- Follow these steps to set up a new site: https://developers.cloudflare.com/turnstile/get-started/
+- Add the Cloudflare Turnstile widget to your site: https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/
+
+## Code
+
+Create a new function in your project:
+
+```bash
+supabase functions new cloudflare-turnstile
+```
+
+And add the code to the `index.ts` file:
+
+```ts index.ts
+import { serve } from 'https://deno.land/std@0.131.0/http/server.ts'
+import { corsHeaders } from '../_shared/cors.ts'
+
+console.log('Hello from Cloudflare Trunstile!')
+
+function ips(req: Request) {
+ return req.headers.get('x-forwarded-for')?.split(/\s*,\s*/)
+}
+
+serve(async (req) => {
+ // This is needed if you're planning to invoke your function from a browser.
+ if (req.method === 'OPTIONS') {
+ return new Response('ok', { headers: corsHeaders })
+ }
+
+ const { token } = await req.json()
+ const clientIps = ips(req) || ['']
+ const ip = clientIps[0]
+
+ // Validate the token by calling the
+ // "/siteverify" API endpoint.
+ let formData = new FormData()
+ formData.append('secret', Deno.env.get('CLOUDFLARE_SECRET_KEY') ?? '')
+ formData.append('response', token)
+ formData.append('remoteip', ip)
+
+ const url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify'
+ const result = await fetch(url, {
+ body: formData,
+ method: 'POST',
+ })
+
+ const outcome = await result.json()
+ console.log(outcome)
+ if (outcome.success) {
+ return new Response('success', { headers: corsHeaders })
+ }
+ return new Response('failure', { headers: corsHeaders })
+})
+```
+
+## Deploy the server-side validation Edge Functions
+
+- https://developers.cloudflare.com/turnstile/get-started/server-side-validation/
+
+```bash
+supabase functions deploy cloudflare-turnstile
+supabase secrets set CLOUDFLARE_TURNSTILE_SECRET_KEY=your_secret_key
+```
+
+## Invoke the function from your site
+
+```js
+const { data, error } = await supabase.functions.invoke('cloudflare-turnstile', {
+ body: { token },
+})
+```
+
+export const Page = ({ children }) =>
+
+export default Page
diff --git a/apps/docs/pages/guides/functions/examples/github-actions.mdx b/apps/docs/pages/guides/functions/examples/github-actions.mdx
new file mode 100644
index 00000000000..97456f33767
--- /dev/null
+++ b/apps/docs/pages/guides/functions/examples/github-actions.mdx
@@ -0,0 +1,49 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'examples-github-actions',
+ title: 'GitHub Actions',
+ description: 'Deploying Edge Functions with GitHub Actions.',
+}
+
+
+
+
+
+Use the Supabase CLI together with GitHub Actions to automatically deploy our Supabase Edge Functions. [View on GitHub](https://github.com/supabase/supabase/tree/master/examples/edge-functions/supabase/functions/github-action-deploy).
+
+```yaml deploy.yaml
+name: Deploy Function
+
+on:
+ push:
+ branches:
+ - main
+ workflow_dispatch:
+
+jobs:
+ deploy:
+ runs-on: ubuntu-latest
+
+ env:
+ SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
+ PROJECT_ID: zdtdtxajzydjqzuktnqx
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - uses: supabase/setup-cli@v1
+ with:
+ version: 1.0.0
+
+ - run: supabase functions deploy github-action-deploy --project-ref $PROJECT_ID
+```
+
+export const Page = ({ children }) =>
+
+export default Page
diff --git a/apps/docs/pages/guides/functions/examples/og-image.mdx b/apps/docs/pages/guides/functions/examples/og-image.mdx
index 2974d5ef853..e4be6c85796 100644
--- a/apps/docs/pages/guides/functions/examples/og-image.mdx
+++ b/apps/docs/pages/guides/functions/examples/og-image.mdx
@@ -17,6 +17,10 @@ export const meta = {
Generate Open Graph images with Deno and Supabase Edge Functions. [View on GitHub](https://github.com/supabase/supabase/tree/master/examples/edge-functions/supabase/functions/opengraph).
+## Code
+
+Create a `handler.tsx` file to construct the OG image in React:
+
```tsx handler.tsx
import React from 'https://esm.sh/react@18.2.0'
import { ImageResponse } from 'https://deno.land/x/og_edge@0.0.4/mod.ts'
@@ -42,6 +46,8 @@ export default function handler(req: Request) {
}
```
+Create an `index.ts` file to execute the handler on incoming requests:
+
```ts index.ts
import { serve } from 'https://deno.land/std@0.131.0/http/server.ts'
import handler from './handler.tsx'
diff --git a/apps/docs/pages/guides/functions/examples/storage-caching.mdx b/apps/docs/pages/guides/functions/examples/storage-caching.mdx
new file mode 100644
index 00000000000..6e4b6ff604e
--- /dev/null
+++ b/apps/docs/pages/guides/functions/examples/storage-caching.mdx
@@ -0,0 +1,22 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'examples-storage-caching',
+ title: 'Caching Images with Supabase Storage CDN',
+ description: 'Integrate Edge Functions with Supabase Storage to cache images on the Edge (CDN).',
+}
+
+
+
+
+
+Integrate Edge Functions with Supabase Storage to cache images on the Edge (CDN). [View on GitHub](https://github.com/supabase/supabase/tree/master/examples/edge-functions/supabase/functions/og-image-with-storage-cdn).
+
+export const Page = ({ children }) =>
+
+export default Page
diff --git a/apps/docs/pages/guides/functions/examples/stripe-webhooks.mdx b/apps/docs/pages/guides/functions/examples/stripe-webhooks.mdx
new file mode 100644
index 00000000000..5b75bb48878
--- /dev/null
+++ b/apps/docs/pages/guides/functions/examples/stripe-webhooks.mdx
@@ -0,0 +1,22 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'examples-stripe-webhooks',
+ title: 'Handling Stripe Webhooks',
+ description: 'Handling signed Stripe Webhooks with Edge Functions.',
+}
+
+
+
+
+
+Handling signed Stripe Webhooks with Edge Functions. [View on GitHub](https://github.com/supabase/supabase/blob/master/examples/edge-functions/supabase/functions/stripe-webhooks/index.ts).
+
+export const Page = ({ children }) =>
+
+export default Page
diff --git a/apps/docs/pages/guides/functions/examples/telegram-bot.mdx b/apps/docs/pages/guides/functions/examples/telegram-bot.mdx
new file mode 100644
index 00000000000..bac6a45eba2
--- /dev/null
+++ b/apps/docs/pages/guides/functions/examples/telegram-bot.mdx
@@ -0,0 +1,22 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'examples-telegram-bot',
+ title: 'Telegram Bot',
+ description: 'Building a Telegram Bot with Edge Functions.',
+}
+
+
+
+
+
+Handle Telegram Bot Webhooks with the [grammY framework](https://grammy.dev/). grammY is an open source Telegram Bot Framework which makes it easy to handle and respond to incoming messages. [View on GitHub](https://github.com/supabase/supabase/tree/master/examples/edge-functions/supabase/functions/telegram-bot).
+
+export const Page = ({ children }) =>
+
+export default Page
diff --git a/apps/docs/pages/guides/functions/import-maps.mdx b/apps/docs/pages/guides/functions/import-maps.mdx
new file mode 100644
index 00000000000..1509a9cd8a9
--- /dev/null
+++ b/apps/docs/pages/guides/functions/import-maps.mdx
@@ -0,0 +1,53 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'functions-import-maps',
+ title: 'Import Maps',
+ description: 'Using Import Maps.',
+}
+
+Since [Supabase CLI](https://supabase.com/docs/guides/resources/supabase-cli) version `1.33.0` [import maps](https://deno.land/manual@v1.29.2/node/import_maps) can be used with Supabase Edge Functions.
+
+[Import maps](https://github.com/WICG/import-maps#the-import-map) is a web-platform standard that allows you to use bare specifiers with Deno without having to install the Node.js package locally.
+
+So if we want to do the following in our code:
+
+```ts, ignore
+import lodash from "lodash";
+```
+
+We can accomplish this using an import map, and we don't even have to install the `lodash` package locally. We would want to create a JSON file (for example **import_map.json**) with the following:
+
+```json
+{
+ "imports": {
+ "lodash": "https://cdn.skypack.dev/lodash"
+ }
+}
+```
+
+## Import Map Placement
+
+We recommend creating one `import_map.json` within the `/supabase/functions` folder (see [Organizing your Edge Functions](/docs/guides/functions/quickstart#organizing-your-edge-functions)), similar to a `package.json` file, to define imports that can be used across all of your project's functions.
+
+Alternatively, you can create one `import_map.json` file in each function folder, which will take priority over a top-level file.
+
+Lastly, you can override this default behaviour by providing the `--import-map ` flag to the `serve` and `deploy` commands.
+
+## Visual Studio Code Configuration
+
+In order for vscode to understand the imports correctly, you need to specify the `deno.importMap` flag in your `.vscode/settings.json` file:
+
+```json settings.json
+{
+ "deno.enable": true,
+ "deno.unstable": true,
+ "deno.importMap": "./supabase/functions/import_map.json"
+}
+```
+
+For a full guide on developing with Deno in Visual Studio Code, see [this guide](https://deno.land/manual@v1.25.4/vscode_deno).
+
+export const Page = ({ children }) =>
+
+export default Page
diff --git a/apps/docs/pages/guides/functions/local-development.mdx b/apps/docs/pages/guides/functions/local-development.mdx
new file mode 100644
index 00000000000..fffd6ac7072
--- /dev/null
+++ b/apps/docs/pages/guides/functions/local-development.mdx
@@ -0,0 +1,60 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'functions-local-development',
+ title: 'Local Development',
+ description: 'Run your functions locally.',
+}
+
+You can run your Edge Function locally using [`supabase functions serve`](/docs/reference/cli/usage#supabase-functions-serve):
+
+```bash
+supabase start # start the supabase stack
+supabase functions serve hello-world # start the Function watcher
+```
+
+The `functions serve` command has hot-reloading capabilities. It will watch for any changes to your files and restart the Deno server.
+
+### Invoking functions locally
+
+While serving your local Function, you can invoke it using curl:
+
+```bash
+curl --request POST 'http://localhost:54321/functions/v1/hello-world' \
+ --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24ifQ.625_WdcF3KHqz5amU0x2X5WWHP-OEs_4qj0ssLNHzTs' \
+ --header 'Content-Type: application/json' \
+ --data '{ "name":"Functions" }'
+```
+
+or using one of the [client libraries](/docs#reference-documentation), e.g. using [supabase-js](/docs/reference/javascript/functions-invoke):
+
+```js
+import { createClient } from '@supabase/supabase-js'
+
+// Use the credentials outputted in your terminal when running `supabase start`
+const supabase = createClient(
+ 'http://localhost:54321',
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0'
+)
+
+const { data, error } = await supabase.functions.invoke('hello-world', {
+ body: { name: 'Functions' },
+})
+```
+
+You should see the response `{ "message":"Hello Functions!" }`.
+
+If you execute Function with a different payload the response will change.
+Modify the `--data '{"name":"Functions"}'` line to `--data '{"name":"World"}'` and try invoking the command again!
+
+
+
+- Edge Functions don't serve HTML content (`GET` requests that return `text/html` are rewritten to `text/plain`).
+- The `Authorization` header is required. You can use either the `ANON` key, the `SERVICE_ROLE` key, or a logged-in user's JWT.
+- The Function is proxied through the local API (`http://localhost:54321`)
+
+
+
+export const Page = ({ children }) =>
+
+export default Page
diff --git a/apps/docs/pages/guides/functions/quickstart.mdx b/apps/docs/pages/guides/functions/quickstart.mdx
index 55b9ed617c6..e4e17a3a708 100644
--- a/apps/docs/pages/guides/functions/quickstart.mdx
+++ b/apps/docs/pages/guides/functions/quickstart.mdx
@@ -3,7 +3,7 @@ import Layout from '~/layouts/DefaultGuideLayout'
export const meta = {
id: 'functions-quickstart',
title: 'Edge Functions Quickstart',
- description: 'Globally distributed TypeScript functions.',
+ description: 'Globally distributed TypeScript Functions.',
sidebar_label: 'Quickstart',
}
@@ -55,9 +55,9 @@ If you want to use Edge Functions to handle webhooks (e.g. [Stripe payment webho
-## Execute remote functions
+## Invoking remote functions
-You can execute Edge Functions using curl. Copy the curl command from the Dashboard. It should look like this:
+You can invoke Edge Functions using curl:
```bash
curl --request POST 'https://.functions.supabase.co/hello-world' \
@@ -66,135 +66,61 @@ curl --request POST 'https://.functions.supabase.co/hello-world' \
--data '{ "name":"Functions" }'
```
+
+
If you receive an error `Invalid JWT`, find the `ANON_KEY` of your project in the Dashboard under `Settings > API`.
+
+
+or using one of the [client libraries](/docs#reference-documentation), e.g. using [supabase-js](/docs/reference/javascript/functions-invoke):
+
+```js
+import { createClient } from '@supabase/supabase-js'
+
+// Create a single supabase client for interacting with your database
+const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key')
+
+const { data, error } = await supabase.functions.invoke('hello-world', {
+ body: { name: 'Functions' },
+})
+```
+
After invoking your Edge Function you should see the response `{ "message":"Hello Functions!" }`.
-## Debug functions
+## Database Functions vs Edge Functions
-You can debug your deployed Edge Functions using the "Functions" section of the Dashboard. There are two types debugging tools available:
+For data-intensive operations we recommend using [Database Functions](/docs/guides/database/functions), which are executed within your database
+and can be called remotely using the [REST and GraphQL API](/docs/guides/api).
-- Invocations: shows the Request and Response for each execution.
-- Logs: shows any platform events, including deployments and errors.
+For use-cases which require low-latency we recommend [Edge Functions](/docs/guides/functions), which are globally-distributed and can be written in TypeScript.
-
+## Organizing your Edge Functions
-## Develop locally
-
-You can run your Edge Function locally using [`supabase functions serve`](/docs/reference/cli/usage#supabase-functions-serve):
+We recommend developing “fat functions”. This means that you should develop few large functions, rather than many small functions. One common pattern when developing Functions is that you need to share code between two or more Functions. To do this, you can store any shared code in a folder prefixed with an underscore (`_`). We recommend this folder structure:
```bash
-supabase start # start the supabase stack
-supabase functions serve hello-world # start the Function watcher
+└── supabase
+ ├── functions
+ │ ├── import_map.json # A top-level import map to use across functions.
+ │ ├── _shared
+ │ │ ├── supabaseAdmin.ts # Supabase client with SERVICE_ROLE key.
+ │ │ └── supabaseClient.ts # Supabase client with ANON key.
+ │ │ └── cors.ts # Reusable CORS headers.
+ │ ├── function-one # Use hyphens to name functions.
+ │ │ └── index.ts
+ │ └── function-two
+ │ └── index.ts
+ ├── migrations
+ └── config.toml
```
-The `functions serve` command has hot-reloading capabilities. It will watch for any changes to your files and restart the Deno server.
+## Naming Edge Functions
-### Invoke functions locally
+We recommend using hyphens to name functions because hyphens are the most URL-friendly of all the naming conventions (snake_case, camelCase, PascalCase).
-While serving your local Function, you can execute it using curl:
+## Using HTTP Methods
-```bash
-curl --request POST 'http://localhost:54321/functions/v1/hello-world' \
- --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24ifQ.625_WdcF3KHqz5amU0x2X5WWHP-OEs_4qj0ssLNHzTs' \
- --header 'Content-Type: application/json' \
- --data '{ "name":"Functions" }'
-```
-
-You should see the response `{ "message":"Hello Functions!" }`.
-
-
-Implementation details
-
-- Edge Functions don't serve HTML content (`GET` requests that return `text/html` are rewritten to `text/plain`).
-- The `Authorization` header is required. You can use either the `ANON` key, the `SERVICE_ROLE` key, or a logged-in user's JWT.
-- The Function is proxied through the local API (`http://localhost:54321`)
-
-
-
-
-If you execute Function with a different payload the response will change.
-Modify the `--data '{"name":"Functions"}'` line to `--data '{"name":"World"}'` and try invoking the command again!
-
-## Secrets and Environment Variables
-
-It's common that you will need to use sensitive information or environment-specific variables inside your Edge Functions. You can access these using Deno's built-in handler
-
-```js
-Deno.env.get(MY_SECRET_NAME)
-```
-
-### Default secrets
-
-By default, Edge Functions have access to these secrets:
-
-- `SUPABASE_URL`: The API gateway for your Supabase project.
-- `SUPABASE_ANON_KEY`: The `anon` key for your Supabase API. This is safe to use in a browser when you have [Row Level Security](/docs/guides/auth/row-level-security) enabled.
-- `SUPABASE_SERVICE_ROLE_KEY`: The `service_role` key for your Supabase API. This is safe to use in Edge Functions, but it should NEVER be used in a browser. This key will bypass [Row Level Security](/docs/guides/auth/row-level-security).
-- `SUPABASE_DB_URL`: The URL for your [PostgreSQL database](/docs/guides/database). You can use this to connect directly to your database.
-
-### Local secrets
-
-Let's create a local file for storing our secrets, and inside it we can store a secret `MY_NAME`:
-
-```jsx
-echo "MY_NAME=Yoda" >> ./supabase/.env.local
-```
-
-This creates a new file `./supabase/.env.local` for storing your local development secrets.
-
-
-
-Never check your .env files into Git!
-
-
-
-Now let's access this environment variable `MY_NAME` inside our Function. Anywhere in your function, add this line:
-
-```jsx
-console.log(Deno.env.get('MY_NAME'))
-```
-
-Now we can invoke our function locally, by serving it with our new `.env.local` file:
-
-```bash
-supabase functions serve hello-world --env-file ./supabase/.env.local
-```
-
-When the function starts you should see the name “Yoda” output to the terminal.
-
-### Production secrets
-
-Let's create a `.env` for production. In this case we'll just use the same as our local secrets:
-
-```bash
-cp ./supabase/.env.local ./supabase/.env
-```
-
-This creates a new file `./supabase/.env` for storing your production secrets.
-
-
-
-Never check your `.env` files into Git!
-
-
-
-Let's push all the secrets from the `.env` file to our remote project using [`supabase secrets set`](/docs/reference/cli/usage#supabase-secrets-set):
-
-```bash
-supabase secrets set --env-file ./supabase/.env
-
-# You can also set secrets individually using:
-supabase secrets set MY_NAME=Chewbacca
-```
-
-You don't need to re-deploy after setting your secrets.
-
-To see all the secrets which you have set remotely, use [`supabase secrets list`](/docs/reference/cli/usage#supabase-secrets-list):
-
-```bash
-supabase secrets list
-```
+Edge Functions supports `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, and `OPTIONS`. A function can be designed to perform different actions based on a request's HTTP method. See the [example on building a RESTful service](https://github.com/supabase/supabase/tree/master/examples/edge-functions/supabase/functions/restful-tasks) to learn how to handle different HTTP methods in your function.
## Limitations
diff --git a/apps/docs/pages/guides/functions/schedule-functions.mdx b/apps/docs/pages/guides/functions/schedule-functions.mdx
new file mode 100644
index 00000000000..c5108b55523
--- /dev/null
+++ b/apps/docs/pages/guides/functions/schedule-functions.mdx
@@ -0,0 +1,42 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'schedule-functions',
+ title: 'Schedule Functions',
+ description: 'Schedule Functions with pg_cron.',
+}
+
+The hosted Supabase Platform supports the [`pg_cron` extension](/docs/guides/database/extensions/pgcron), a simple cron-based job scheduler for PostgreSQL that runs inside the database.
+
+In combination with the [`pg_net` extension](/docs/guides/database/extensions/pgnet), this allows us to invoke functions periodically on a set schedule.
+
+## Examples
+
+### Invoke Function every minute
+
+Make a POST request to a Supabase Edge Function every minute:
+
+```sql
+select
+ cron.schedule(
+ 'invoke-function-every-minute',
+ '* * * * *', -- every minute
+ $$
+ select
+ net.http_post(
+ url:='https://project-ref.functions.supabase.co/function-name',
+ headers:='{"Content-Type": "application/json", "Authorization": "Bearer YOUR_ANON_KEY"}'::jsonb,
+ body:=concat('{"time": "', now(), '"}')::jsonb
+ ) as request_id;
+ $$
+ );
+```
+
+## Resources
+
+- [`pg_net` extension](/docs/guides/database/extensions/pgnet)
+- [`pg_cron` extension](/docs/guides/database/extensions/pgcron)
+
+export const Page = ({ children }) =>
+
+export default Page
diff --git a/apps/docs/pages/guides/functions/secrets.mdx b/apps/docs/pages/guides/functions/secrets.mdx
new file mode 100644
index 00000000000..dd51094d374
--- /dev/null
+++ b/apps/docs/pages/guides/functions/secrets.mdx
@@ -0,0 +1,89 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'functions-secrets',
+ title: 'Secrets and Environment Variables',
+ description: 'Managing secrets and environment variables.',
+}
+
+It's common that you will need to use sensitive information or environment-specific variables inside your Edge Functions. You can access these using Deno's built-in handler
+
+```js
+Deno.env.get(MY_SECRET_NAME)
+```
+
+### Default secrets
+
+By default, Edge Functions have access to these secrets:
+
+- `SUPABASE_URL`: The API gateway for your Supabase project.
+- `SUPABASE_ANON_KEY`: The `anon` key for your Supabase API. This is safe to use in a browser when you have [Row Level Security](/docs/guides/auth/row-level-security) enabled.
+- `SUPABASE_SERVICE_ROLE_KEY`: The `service_role` key for your Supabase API. This is safe to use in Edge Functions, but it should NEVER be used in a browser. This key will bypass [Row Level Security](/docs/guides/auth/row-level-security).
+- `SUPABASE_DB_URL`: The URL for your [PostgreSQL database](/docs/guides/database). You can use this to connect directly to your database.
+
+### Local secrets
+
+Let's create a local file for storing our secrets, and inside it we can store a secret `MY_NAME`:
+
+```jsx
+echo "MY_NAME=Yoda" >> ./supabase/.env.local
+```
+
+This creates a new file `./supabase/.env.local` for storing your local development secrets.
+
+
+
+Never check your .env files into Git!
+
+
+
+Now let's access this environment variable `MY_NAME` inside our Function. Anywhere in your function, add this line:
+
+```jsx
+console.log(Deno.env.get('MY_NAME'))
+```
+
+Now we can invoke our function locally, by serving it with our new `.env.local` file:
+
+```bash
+supabase functions serve hello-world --env-file ./supabase/.env.local
+```
+
+When the function starts you should see the name “Yoda” output to the terminal.
+
+### Production secrets
+
+Let's create a `.env` for production. In this case we'll just use the same as our local secrets:
+
+```bash
+cp ./supabase/.env.local ./supabase/.env
+```
+
+This creates a new file `./supabase/.env` for storing your production secrets.
+
+
+
+Never check your `.env` files into Git!
+
+
+
+Let's push all the secrets from the `.env` file to our remote project using [`supabase secrets set`](/docs/reference/cli/usage#supabase-secrets-set):
+
+```bash
+supabase secrets set --env-file ./supabase/.env
+
+# You can also set secrets individually using:
+supabase secrets set MY_NAME=Chewbacca
+```
+
+You don't need to re-deploy after setting your secrets.
+
+To see all the secrets which you have set remotely, use [`supabase secrets list`](/docs/reference/cli/usage#supabase-secrets-list):
+
+```bash
+supabase secrets list
+```
+
+export const Page = ({ children }) =>
+
+export default Page
diff --git a/apps/docs/pages/guides/integrations/prisma.mdx b/apps/docs/pages/guides/integrations/prisma.mdx
index 6a80e95fee6..840028a00c7 100644
--- a/apps/docs/pages/guides/integrations/prisma.mdx
+++ b/apps/docs/pages/guides/integrations/prisma.mdx
@@ -68,7 +68,7 @@ By default, Prisma migrations will try to drop the `postgres` database, which ca
Create a shadow database in your PostgreSQL server within the same Supabase project using the `psql` CLI and the `DATABASE_URL` from the previous steps (or use the local database).
```bash
-psql postgresql://postgres:[YOUR-PASSWORD]@db.vdbnhqozmlzdsaejdxwr.supabase.red:5432
+psql postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432
```
After you connect to your project's PostgreSQL instance, create another database (e.g., `postgres_shadow`):
@@ -83,8 +83,8 @@ In the `.env` file, update `DATABASE_URL` and `SHADOW_DATABASE_URL` to the conne
```env
# .env
-DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.vdbnhqozmlzdsaejdxwr.supabase.co:5432/postgres"
-SHADOW_DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.vdbnhqozmlzdsaejdxwr.supabase.co:5432/postgres_shadow"
+DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres"
+SHADOW_DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres_shadow"
```
In the `schema.prisma` file, change the `provider` from "sqlite" to `"postgresql"` and add the `shadowDatabaseUrl` property.
@@ -145,8 +145,8 @@ When migrating, you need to use the non-pooled connection URL (like the one used
```env
# .env
-DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.vdbnhqozmlzdsaejdxwr.supabase.co:6543/postgres?pgbouncer=true&connection_limit=1"
-SHADOW_DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.vdbnhqozmlzdsaejdxwr.supabase.co:5432/postgres_shadow"
+DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:6543/postgres?pgbouncer=true&connection_limit=1"
+SHADOW_DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres_shadow"
```
Prisma Migrate uses database transactions to check out the current state of the database and the migrations table. However, the Migration Engine is designed to use a single connection to the database, and does not support connection pooling with PgBouncer. If you attempt to run Prisma Migrate commands in any environment that uses PgBouncer for connection pooling, you might see the following error:
diff --git a/apps/www/_blog/2022-08-16-supabase-js-v2.mdx b/apps/www/_blog/2022-08-16-supabase-js-v2.mdx
index d7986434a97..07cf3fd54dc 100644
--- a/apps/www/_blog/2022-08-16-supabase-js-v2.mdx
+++ b/apps/www/_blog/2022-08-16-supabase-js-v2.mdx
@@ -13,7 +13,7 @@ toc_depth: 3
@@ -309,7 +309,7 @@ Update today by running:
npm i @supabase/supabase-js@2
```
-[Migration guide](https://supabase.com/docs/reference/javascript/upgrade-guide)
+[Migration guide](https://supabase.com/docs/reference/javascript/v1/upgrade-guide)
We'll continuing merging security fixes to v1, with maintenance patches for the next three months.
@@ -329,6 +329,6 @@ We'll continuing merging security fixes to v1, with maintenance patches for the
## supabase-js v2 resources
- [v2 Documentation](https://supabase.com/docs/reference/javascript)
-- [Migration guide](https://supabase.com/docs/reference/javascript/upgrade-guide)
+- [Migration guide](https://supabase.com/docs/reference/javascript/v1/upgrade-guide)
- [Next.js quickstart guide](/docs/guides/with-nextjs)
- [Examples](https://github.com/supabase/supabase/tree/master/examples)
diff --git a/apps/www/_blog/2022-10-20-supabase-js-v2-released.mdx b/apps/www/_blog/2022-10-20-supabase-js-v2-released.mdx
index 6e17afd4d14..6c2fca19cd8 100644
--- a/apps/www/_blog/2022-10-20-supabase-js-v2-released.mdx
+++ b/apps/www/_blog/2022-10-20-supabase-js-v2-released.mdx
@@ -2,7 +2,7 @@
title: 'supabase-js v2 Released'
description: We've released supabase-js v2. Updated examples, quickstarts, and an improved experience.
author: thor_schaeff
-image: supabase-js-v2-release/supabase-js.jpg
+image: supabase-js-v2-release/supabase-js.jpg
thumb: supabase-js-v2-release/supabase-js.jpg
tags:
- launch-week
@@ -10,17 +10,17 @@ date: '2022-10-20'
toc_depth: 3
---
-During our [last Launch Week](/launch-week) we presented the [release candidate for supabase-js v2](/blog/supabase-js-v2). Since then we've been busy incorporating your feedback, [updating the docs](/docs/reference/javascript/), [examples](https://github.com/supabase/supabase/tree/master/examples), [quickstart guides](/docs/guides/with-nextjs), and putting a [migration guide](/docs/reference/javascript/upgrade-guide) together.
+During our [last Launch Week](/launch-week) we presented the [release candidate for supabase-js v2](/blog/supabase-js-v2). Since then we've been busy incorporating your feedback, [updating the docs](/docs/reference/javascript/), [examples](https://github.com/supabase/supabase/tree/master/examples), [quickstart guides](/docs/guides/with-nextjs), and putting a [migration guide](/docs/reference/javascript/v1/upgrade-guide) together.
## What is new in v2?
-Enhanced TypeScript support built right in was the big one! Now you can use the CLI to generate types, directly from your database.
+Enhanced TypeScript support built right in was the big one! Now you can use the CLI to generate types, directly from your database.
-Plus v2 comes with lots of improvements that solved some of the largest pain-points highlighted by our users. Your feedback help us improve: you speak, we listen.
+Plus v2 comes with lots of improvements that solved some of the largest pain-points highlighted by our users. Your feedback help us improve: you speak, we listen.
Read all the updates and the differences with v1 on the [announcement blog post](/blog/supabase-js-v2)
-## Acknowledgements
+## Acknowledgements
It truly takes a village, well, in this case an entire community, and we want to thank you all for your feedback, and contributions!
@@ -40,7 +40,7 @@ Special shout outs to: [@vejja](https://github.com/vejja), [@pixtron](https://gi
## Links
- [Documentation](/docs/reference/javascript)
-- [Migration Guide](/docs/reference/javascript/upgrade-guide)
+- [Migration Guide](/docs/reference/javascript/v1/upgrade-guide)
- [Quickstart Guides](/docs/guides/with-nextjs)
- [Examples (GitHub)](https://github.com/supabase/supabase/tree/master/examples)
- [Release Notes](/docs/reference/javascript/release-notes)
diff --git a/apps/www/_blog/2022-10-21-supabase-flutter-sdk-v1-released.mdx b/apps/www/_blog/2022-10-21-supabase-flutter-sdk-v1-released.mdx
index e7fdabdc869..92aed5cbb3b 100644
--- a/apps/www/_blog/2022-10-21-supabase-flutter-sdk-v1-released.mdx
+++ b/apps/www/_blog/2022-10-21-supabase-flutter-sdk-v1-released.mdx
@@ -2,7 +2,7 @@
title: 'supabase-flutter v1 Released'
description: We've released supabase-flutter v1. More intuitive way of accessing Supabase from your Flutter application.
author: tyler_shukert
-image: flutter-v1-release/flutter_v1_official_release.jpeg
+image: flutter-v1-release/flutter_v1_official_release.jpeg
thumb: flutter-v1-release/flutter_v1_official_release.jpeg
tags:
- flutter
@@ -11,7 +11,7 @@ date: '2022-10-21'
toc_depth: 3
---
-A few months ago, we announced a [developer preview version of supabase-flutter SDK](https://supabase.com/blog/supabase-flutter-sdk-1-developer-preview). Since then, we have heard a lot of amazing feedback from the community, and have been improving it. Today, we are happy to announce the stable v1 of [supabase-flutter](https://pub.dev/packages/supabase_flutter). You can also find the updated [quick start guide](https://supabase.com/docs/guides/with-flutter), [documentation](https://supabase.com/docs/reference/dart) and a [migration guide from v0](https://supabase.com/docs/reference/dart/upgrade-guide).
+A few months ago, we announced a [developer preview version of supabase-flutter SDK](https://supabase.com/blog/supabase-flutter-sdk-1-developer-preview). Since then, we have heard a lot of amazing feedback from the community, and have been improving it. Today, we are happy to announce the stable v1 of [supabase-flutter](https://pub.dev/packages/supabase_flutter). You can also find the updated [quick start guide](https://supabase.com/docs/guides/with-flutter), [documentation](https://supabase.com/docs/reference/dart) and a [migration guide from v0](https://supabase.com/docs/reference/dart/v0/upgrade-guide).
## What is new in v1?
@@ -97,7 +97,7 @@ It required massive support from the community to bring the supabase-flutter to
- [Install supabase-flutter v1.0](https://pub.dev/packages/supabase_flutter)
- [supabase-flutter documentation](https://supabase.com/docs/reference/dart/)
-- [v0 to v1 migration guide](https://supabase.com/docs/reference/dart/upgrade-guide)
+- [v0 to v1 migration guide](https://supabase.com/docs/reference/dart/v0/upgrade-guide)
- [Flutter Tutorial: building a Flutter chat app](https://supabase.com/blog/flutter-tutorial-building-a-chat-app)
- [Flutter Tutorial - Part 2: Authentication and Authorization with RLS](https://supabase.com/blog/flutter-authentication-and-authorization-with-rls)
- [Build a Flutter app with Very Good CLI and Supabase](https://verygood.ventures/blog/flutter-app-very-good-cli-supabase)
diff --git a/apps/www/data/Community.tsx b/apps/www/data/Community.tsx
index 4a48cca53dd..ea9573cdcc4 100644
--- a/apps/www/data/Community.tsx
+++ b/apps/www/data/Community.tsx
@@ -30,7 +30,7 @@ const data: CommunityItem[] = [
},
{
title: 'GitHub',
- stat: '42,000+',
+ stat: '44,000+',
statLabel: 'GitHub stars',
img: 'github.png',
invertImgDarkMode: true,
@@ -42,7 +42,7 @@ const data: CommunityItem[] = [
},
{
title: 'Twitter',
- stat: '50,000+',
+ stat: '54,000+',
statLabel: 'Followers',
img: 'twitter.png',
detail: () => (
@@ -53,7 +53,7 @@ const data: CommunityItem[] = [
},
{
title: 'Discord',
- stat: '10,000+',
+ stat: '12,000+',
statLabel: 'SupaTroopers',
img: 'discord.png',
detail: () => (
diff --git a/apps/www/lib/redirects.js b/apps/www/lib/redirects.js
index 1e992b67d9e..420340205b9 100644
--- a/apps/www/lib/redirects.js
+++ b/apps/www/lib/redirects.js
@@ -1554,6 +1554,11 @@ module.exports = [
source: '/docs/guides/functions/examples',
destination: '/docs/guides/functions',
},
+ {
+ permanent: true,
+ source: '/docs/guides/functions/best-practices',
+ destination: '/docs/guides/functions/quickstart',
+ },
{
permanent: true,
source: '/projects',
@@ -1886,4 +1891,14 @@ module.exports = [
source: '/legal/soc2',
destination: 'https://forms.supabase.com/soc2',
},
+ {
+ permanent: true,
+ source: '/docs/reference/javascript/upgrade-guide',
+ destination: '/docs/reference/javascript/v1/upgrade-guide',
+ },
+ {
+ permanent: true,
+ source: '/docs/reference/dart/upgrade-guide',
+ destination: '/docs/reference/dart/v0/upgrade-guide',
+ },
]
diff --git a/apps/www/pages/realtime/Realtime.tsx b/apps/www/pages/realtime/Realtime.tsx
index cc062d0bde4..633b7bc7bae 100644
--- a/apps/www/pages/realtime/Realtime.tsx
+++ b/apps/www/pages/realtime/Realtime.tsx
@@ -238,7 +238,7 @@ function RealtimePage() {
,
]}
// [TODO] Point to the correct docs URL
- documentation_link={'/docs/guides//docs/guides/realtime/broadcast'}
+ documentation_link={'/docs/guides/realtime#broadcast'}
/>
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index db91090408e..74bd0f1e828 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -114,7 +114,7 @@ services:
PORT: 4000
DB_HOST: ${POSTGRES_HOST}
DB_PORT: ${POSTGRES_PORT}
- DB_USER: ${POSTGRES_USER}
+ DB_USER: supabase_admin
DB_PASSWORD: ${POSTGRES_PASSWORD}
DB_NAME: ${POSTGRES_DB}
DB_AFTER_CONNECT_QUERY: 'SET search_path TO _realtime'
diff --git a/spec/common-client-libs-sections.json b/spec/common-client-libs-sections.json
index c290fb91859..8f4dc1f62d0 100644
--- a/spec/common-client-libs-sections.json
+++ b/spec/common-client-libs-sections.json
@@ -650,7 +650,7 @@
{
"id": "invoke",
"title": "Invoke a function",
- "slug": "auth-admin-invoke",
+ "slug": "functions-invoke",
"product": "functions",
"type": "function"
}
diff --git a/spec/enrichments/tsdoc_v2/combined.json b/spec/enrichments/tsdoc_v2/combined.json
index 0c72523e032..57242f4b5bf 100644
--- a/spec/enrichments/tsdoc_v2/combined.json
+++ b/spec/enrichments/tsdoc_v2/combined.json
@@ -79596,7 +79596,7 @@
"kindString": "Call signature",
"flags": {},
"comment": {
- "shortText": "Retrieves the URL for an asset in a public bucket.\nThis function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset."
+ "shortText": "A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.\nThis function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset."
},
"parameters": [
{
diff --git a/spec/enrichments/tsdoc_v2/storage.json b/spec/enrichments/tsdoc_v2/storage.json
index 475ba699fc3..fb8baa1c895 100644
--- a/spec/enrichments/tsdoc_v2/storage.json
+++ b/spec/enrichments/tsdoc_v2/storage.json
@@ -5471,7 +5471,7 @@
"kindString": "Call signature",
"flags": {},
"comment": {
- "shortText": "Retrieves the URL for an asset in a public bucket.\nThis function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset."
+ "shortText": "A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.\nThis function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset."
},
"parameters": [
{
diff --git a/spec/enrichments/tsdoc_v2/storage_dereferenced.json b/spec/enrichments/tsdoc_v2/storage_dereferenced.json
index 634dd23b469..53596ea9650 100644
--- a/spec/enrichments/tsdoc_v2/storage_dereferenced.json
+++ b/spec/enrichments/tsdoc_v2/storage_dereferenced.json
@@ -5875,7 +5875,7 @@
"kindString": "Call signature",
"flags": {},
"comment": {
- "shortText": "Retrieves the URL for an asset in a public bucket.\nThis function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset."
+ "shortText": "A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.\nThis function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset."
},
"parameters": [
{
diff --git a/spec/supabase_js_v2.yml b/spec/supabase_js_v2.yml
index 7e220e2dc23..0cd16c93dbd 100644
--- a/spec/supabase_js_v2.yml
+++ b/spec/supabase_js_v2.yml
@@ -3429,8 +3429,8 @@ functions:
code: |
```ts
const { data, error } = await supabase
- .from('cities')
- .select('name', 'country_id')
+ .from('countries')
+ .select('id', 'name')
.order('id', { ascending: false })
```
data:
diff --git a/studio/components/grid/components/header/Header.tsx b/studio/components/grid/components/header/Header.tsx
index 1b3e8ae89bc..4ad75e4eaef 100644
--- a/studio/components/grid/components/header/Header.tsx
+++ b/studio/components/grid/components/header/Header.tsx
@@ -40,10 +40,7 @@ const Header: FC = ({ sorts, filters, onAddColumn, onAddRow, header
onAddRow={onAddRow}
/>
)}
-
-
- {headerActions}
-
+
{headerActions}
)
}
@@ -77,6 +74,7 @@ const DefaultHeader: FC = ({ sorts, filters, onAddColumn, on
return (
+ Policies restrict, on a per-user basis, which rows can be returned by normal
+ queries, or inserted, updated, or deleted by data modification commands.
+
+
+ This is also known as Row-Level Security (RLS). Each policy is attached to a
+ table, and the policy is executed each time its accessed.
+
+
+ }
+ />
+
+ Create a table in this schema first before creating a policy.
+
Restrict access to your table by enabling RLS and writing Postgres policies.
-
- If RLS is not enabled, anyone with the anon key can modify and delete your data.
+ RLS is secure by default - all normal access to this table must be allowed by a
+ policy.
{!tableFields.isRLSEnabled && (
- Turning off RLS means that you are allowing anonymous access to your table
-
- }
- />
+ title="Turning off RLS means that you are allowing anonymous access to your table"
+ >
+ As such, anyone with the anonymous key can modify or delete your data.
+
)}
>
}
diff --git a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
index 58e2adba72d..36798d285ea 100644
--- a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
@@ -5,11 +5,11 @@ import { find, isUndefined } from 'lodash'
import { PostgresColumn, PostgresTable } from '@supabase/postgres-meta'
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { SchemaView } from 'types'
import { checkPermissions, useFlag, useStore } from 'hooks'
import GridHeaderActions from './GridHeaderActions'
import NotFoundState from './NotFoundState'
import SidePanelEditor from './SidePanelEditor'
-import { SchemaView } from 'components/layouts/TableEditorLayout/TableEditorLayout.types'
import { Dictionary, parseSupaTable, SupabaseGrid, SupabaseGridRef } from 'components/grid'
interface Props {
@@ -81,7 +81,7 @@ const TableGridEditor: FC = ({
// @ts-ignore
const schema = meta.schemas.list().find((schema) => schema.name === selectedSchema)
- const isViewSelected = Object.keys(selectedTable).length === 2
+ const isViewSelected = !Object.keys(selectedTable).includes('rls_enabled')
const isForeignTableSelected = meta.foreignTables.byId(selectedTable.id) !== undefined
const isLocked = meta.excludedSchemas.includes(schema?.name ?? '')
const canUpdateTables = checkPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'tables')
diff --git a/studio/components/layouts/AuthLayout/AuthLayout.tsx b/studio/components/layouts/AuthLayout/AuthLayout.tsx
index 8fa69472d88..f747c9adf22 100644
--- a/studio/components/layouts/AuthLayout/AuthLayout.tsx
+++ b/studio/components/layouts/AuthLayout/AuthLayout.tsx
@@ -28,6 +28,7 @@ const AuthLayout: FC = ({ title, children }) => {
meta.policies.load()
meta.tables.load()
meta.roles.load()
+ meta.schemas.load()
}
}, [ui.selectedProject?.ref])
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx
index 0f4944909fc..f083736a6cb 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx
@@ -20,7 +20,10 @@ const FeedbackDropdown = () => {
return (
setIsOpen(e)}
+ onOpenChange={(e) => {
+ setIsOpen(e)
+ if (!e) setScreenshot(undefined)
+ }}
size="content"
side="bottom"
align="end"
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackWidget.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackWidget.tsx
index a8defc57682..a8b8ec910f7 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackWidget.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackWidget.tsx
@@ -1,14 +1,14 @@
import Link from 'next/link'
-import { useState, useEffect, useRef, FC } from 'react'
+import { useState, useEffect, useRef, FC, ChangeEvent } from 'react'
import { useRouter } from 'next/router'
-import * as Tooltip from '@radix-ui/react-tooltip'
import { toPng } from 'html-to-image'
-import { Button, Input, Popover, IconCamera, IconX } from 'ui'
+import { Button, Input, Popover, IconCamera, IconX, IconImage, Dropdown, IconUpload } from 'ui'
import { useStore } from 'hooks'
import { post } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { convertB64toBlob, uploadAttachment } from './FeedbackDropdown.utils'
+import { timeout } from 'lib/helpers'
interface Props {
onClose: () => void
@@ -30,6 +30,7 @@ const FeedbackWidget: FC = ({
const { ui } = useStore()
const inputRef = useRef(null)
+ const uploadButtonRef = useRef()
const [isSending, setSending] = useState(false)
const [isSavingScreenshot, setIsSavingScreenshot] = useState(false)
@@ -42,7 +43,7 @@ const FeedbackWidget: FC = ({
setFeedback(e.target.value)
}
- const captureScreenshot = () => {
+ const captureScreenshot = async () => {
setIsSavingScreenshot(true)
function filter(node: HTMLElement) {
@@ -52,6 +53,8 @@ const FeedbackWidget: FC = ({
return true
}
+ // Give time for dropdown to close
+ await timeout(100)
toPng(document.body, { filter })
.then((dataUrl: any) => setScreenshot(dataUrl))
.catch((error: any) => {
@@ -67,6 +70,18 @@ const FeedbackWidget: FC = ({
})
}
+ const onFilesUpload = async (event: ChangeEvent) => {
+ event.persist()
+ const [file] = event.target.files || (event as any).dataTransfer.items
+
+ const reader = new FileReader()
+ reader.onload = function (event) {
+ setScreenshot(event.target?.result as string)
+ }
+ reader.readAsDataURL(file)
+ event.target.value = ''
+ }
+
const sendFeedback = async () => {
if (feedback.length === 0 && screenshot !== undefined) {
return ui.setNotification({
@@ -97,7 +112,7 @@ const FeedbackWidget: FC = ({
}
return (
-
- Policies restrict, on a per-user basis, which rows can be returned by normal
- queries, or inserted, updated, or deleted by data modification commands.
-
-
- This is also known as Row-Level Security (RLS). Each policy is attached to a
- table, and the policy is executed everytime a time is accessed.
-
-
- }
- />
-
- A table within the public schema is required before you can create a Row-Level
- Security policy.
-