Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions apps/docs/content/guides/realtime/authorization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/guides/realtime/broadcast.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function DatabaseBackupsNav({ active }: Props) {
<div className="flex items-center gap-1">
Restore to new project{' '}
<Badge size="small" className="!text-[10px] px-1.5 py-0">
New
Beta
</Badge>
</div>
),
Expand Down
Loading