Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

docs(realtime): JWT claims can be accessed when authorising channels (#38049)

Eduardo Gurgel07dfb9a542f0
diff --git a/apps/docs/content/guides/realtime/authorization.mdx b/apps/docs/content/guides/realtime/authorization.mdx
index 66c854efcb7..3dd1d59b336 100644
--- a/apps/docs/content/guides/realtime/authorization.mdx
+++ b/apps/docs/content/guides/realtime/authorization.mdx
@@ -50,13 +50,11 @@ Increased RLS complexity can impact database performance and connection time, le
</Admonition>
-## Helper functions
-
-You can use the following helper functions when writing RLS policies:
+## Accessing request information
### `realtime.topic`
-Returns the Channel topic the user is attempting to connect to.
+You can use the `realtime.topic` helper function when writing RLS policies. It returns the Channel topic the user is attempting to connect to.
```sql
create policy "authenticated can read all messages on topic"
@@ -68,6 +66,21 @@ using (
);
```
+### JWT claims
+
+The user claims can be accessed using the `current_setting` function. The claims are available as a JSON object in the `request.jwt.claims` setting.
+
+```sql
+create policy "authenticated with supabase.io email can read all"
+on "realtime"."messages"
+for select
+to authenticated
+using (
+ -- Only users with the email claim ending with @supabase.io
+ (((current_setting('request.jwt.claims'))::json ->> 'email') ~~ '%@supabase.io')
+);
+```
+
## Examples
The following examples use this schema:
diff --git a/apps/docs/content/guides/realtime/broadcast.mdx b/apps/docs/content/guides/realtime/broadcast.mdx
index fec239f875d..18bce679967 100644
--- a/apps/docs/content/guides/realtime/broadcast.mdx
+++ b/apps/docs/content/guides/realtime/broadcast.mdx
@@ -811,7 +811,7 @@ The `realtime.send` function provides the most flexibility by allowing you to br
```sql
SELECT realtime.send (
- to_jsonb ('{}'::text), -- JSONB Payload
+ '{}'::jsonb, -- JSONB Payload
'event', -- Event name
'topic', -- Topic
FALSE -- Public / Private flag