Skip to content

Commit 07dfb9a

Browse files
authored
docs(realtime): JWT claims can be accessed when authorising channels (supabase#38049)
1 parent 53b0491 commit 07dfb9a

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

apps/docs/content/guides/realtime/authorization.mdx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ Increased RLS complexity can impact database performance and connection time, le
5050

5151
</Admonition>
5252

53-
## Helper functions
54-
55-
You can use the following helper functions when writing RLS policies:
53+
## Accessing request information
5654

5755
### `realtime.topic`
5856

59-
Returns the Channel topic the user is attempting to connect to.
57+
You can use the `realtime.topic` helper function when writing RLS policies. It returns the Channel topic the user is attempting to connect to.
6058

6159
```sql
6260
create policy "authenticated can read all messages on topic"
@@ -68,6 +66,21 @@ using (
6866
);
6967
```
7068

69+
### JWT claims
70+
71+
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.
72+
73+
```sql
74+
create policy "authenticated with supabase.io email can read all"
75+
on "realtime"."messages"
76+
for select
77+
to authenticated
78+
using (
79+
-- Only users with the email claim ending with @supabase.io
80+
(((current_setting('request.jwt.claims'))::json ->> 'email') ~~ '%@supabase.io')
81+
);
82+
```
83+
7184
## Examples
7285

7386
The following examples use this schema:

apps/docs/content/guides/realtime/broadcast.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ The `realtime.send` function provides the most flexibility by allowing you to br
811811

812812
```sql
813813
SELECT realtime.send (
814-
to_jsonb ('{}'::text), -- JSONB Payload
814+
'{}'::jsonb, -- JSONB Payload
815815
'event', -- Event name
816816
'topic', -- Topic
817817
FALSE -- Public / Private flag

0 commit comments

Comments
 (0)