Files
supabase/apps/docs/content/guides/auth/auth-anonymous.mdx
Miranda Limonczenko 58b468916c docs(auth): Solve eval for Anonymous sign-in page (#53489)
Closes DOCS-1676

## Problem

The drafted Eval for this guide has one failing check. This PR fixes
that check and also runs the `edit-the-docs` and `test-the-docs` skill
to improve the page as a whole.

The Anonymous Sign-Ins guide tells readers to check the `is_anonymous`
JWT claim in RLS policies. When a guest links an email, phone, or OAuth
identity, the user becomes permanent at once, but the token the client
holds keeps `is_anonymous: true` until it refreshes. A policy on the
claim refuses that new customer with `42501` until then.

## What changed

- **Access control:** a caution on the stale claim, and a policy that
reads `auth.users.is_anonymous` through a `security definer` function in
a non-exposed schema with `search_path = ''`.
- **Convert an anonymous user:** a "Refresh the session after linking"
step with `refreshSession()`.
- **Whole-page edit**, one commit per change type:
- Style: wording, word list, sentence-case and imperative headings, no
time-anchored text.
- Structure (moves only): Access control before Convert, identity
conflicts under Convert, the Next.js caution under Sign in.
- Technical: the `anon` key uses the `anon` role, not `anonymous`; the
opening caution no longer says to check the JWT claim; the
existing-account sample throws instead of a top-level `return`.

Renamed headings with no inbound links: Resolving identity conflicts,
Linking an anonymous user to an existing account, Automatic cleanup.
`#access-control` (Studio) and `#link-an-email--phone-identity` are
unchanged.

## Eval on the preview

`build-docs-016-auth-anonymous` with `REFERENCE` pointed at the preview,
3 runs ([workflow
run](https://github.com/supabase/evals/actions/runs/43983385855)).

| Run | Score | Guest who just made an account can post a review |
Failed check |
| --- | --- | --- | --- |
| Baseline (published page) | 9/10 in all 3 runs | Fail in all 3 | Guest
who just made an account can post a review |
| 1 | 10/10 | Pass | None |
| 2 | 9/10 | Pass | Agent read the guide |
| 3 | 9/10 | Pass | Agent read the guide |

All 3 runs fetched the preview and wrote the `security definer` policy.
The guide-read check only counts fetches from `supabase.com`, so it
can't pass on a preview. Run 1 passed it because that agent also opened
the published page.

## Manual testing

1. Open the [Anonymous sign-ins
preview](https://docs-git-docs-anonymous-claim-refresh-supabase.vercel.app/docs/guides/auth/auth-anonymous).
2. Check the new caution and function example under **Access control**,
and the new **Refresh the session after linking** section.
3. Click the anchor links between the two sections and to the RLS guide.
2026-12-01 10:13:18 -08:00

148 lines
5.8 KiB
Plaintext

---
id: 'auth-anonymous'
title: 'Anonymous sign-ins'
subtitle: 'Create and use anonymous users to authenticate with Supabase'
description: 'Learn how anonymous users differ from permanent users, how to sign one in, and what limits apply, so you can decide when to let guests use your project.'
---
[Enable anonymous sign-ins](/dashboard/project/_/auth/providers) to give users an authenticated experience without asking for an email address, password, OAuth provider, or other personally identifiable information (PII). Later, the user can link an authentication method and become a permanent user. On a self-hosted or local project, enable it in the [CLI configuration](/docs/guides/local-development/cli/config) instead.
## How anonymous users differ
An anonymous user behaves like a permanent user, but loses access to their account when they sign out, clear browsing data, or use another device. Don't confuse an anonymous user with the `anon` API key, which doesn't create a user at all.
| | Anonymous user | Permanent user | `anon` API key |
| --------------------------------- | ------------------------------- | --------------- | -------------- |
| Creates a user | Yes, with `signInAnonymously()` | Yes | No |
| Postgres role | `authenticated` | `authenticated` | `anon` |
| `is_anonymous` claim | `true` | `false` | None |
| Survives sign-out or a new device | No | Yes | Not applicable |
<Admonition type="caution">
Review your existing RLS policies before enabling anonymous sign-ins. Anonymous users use the `authenticated` role, so any policy written for signed-in users also applies to them. To tell anonymous users apart from permanent users, see [Restrict anonymous user access](/docs/guides/auth/auth-anonymous/access-control).
</Admonition>
## Sign in anonymously
<Tabs
scrollable
size="small"
type="underlined"
defaultActiveId="js"
queryGroup="language"
>
<TabPanel id="js" label="JavaScript">
Call the [`signInAnonymously()`](/docs/reference/javascript/auth-signinanonymously) method:
```js
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...')
// ---cut---
const { data, error } = await supabase.auth.signInAnonymously()
```
</TabPanel>
<$Show if="sdk:dart">
<TabPanel id="dart" label="Flutter">
Call the [`signInAnonymously()`](/docs/reference/dart/auth-signinanonymously) method:
```dart
await supabase.auth.signInAnonymously();
```
</TabPanel>
</$Show>
<$Show if="sdk:swift">
<TabPanel id="swift" label="Swift">
Call the [`signInAnonymously()`](/docs/reference/swift/auth-signinanonymously) method:
```swift
let session = try await supabase.auth.signInAnonymously()
```
</TabPanel>
</$Show>
<$Show if="sdk:kotlin">
<TabPanel id="kotlin" label="Kotlin">
Call the [`signInAnonymously()`](/docs/reference/kotlin/auth-signinanonymously) method:
```kotlin
supabase.auth.signInAnonymously()
```
</TabPanel>
</$Show>
<$Show if="sdk:python">
<TabPanel id="python" label="Python">
Call the [`sign_in_anonymously()`](/docs/reference/python/auth-signinanonymously) method:
```python
response = supabase.auth.sign_in_anonymously()
```
</TabPanel>
</$Show>
<$Show if="sdk:csharp">
<TabPanel id="csharp" label="C#">
Call the [`SignInAnonymously()`](/docs/reference/csharp/auth-signinanonymously) method:
```c#
var session = await supabase.Auth.SignInAnonymously();
```
</TabPanel>
</$Show>
</Tabs>
<Admonition type="caution" title="Use dynamic rendering with Next.js">
Next.js static page rendering can cache user metadata and serve it to other anonymous users. Use dynamic page rendering instead.
</Admonition>
## Convert an anonymous user to a permanent user [#convert-an-anonymous-user-to-a-permanent-user]
To convert an anonymous user, see [Convert an anonymous user](/docs/guides/auth/auth-anonymous/convert).
## Abuse prevention and rate limits
Because anonymous users are stored in your database, bad actors can abuse the endpoint to inflate your [database size](/docs/guides/platform/database-size). [Enable invisible CAPTCHA or Cloudflare Turnstile](/docs/guides/auth/auth-captcha) to prevent abuse of anonymous sign-ins. Anonymous sign-ins have an IP-based rate limit of 30 requests per hour, which you can change in the [dashboard](/dashboard/project/_/auth/rate-limits). For every rate limit, see [Rate limiting, resource allocation, and abuse prevention](/docs/guides/deployment/going-into-prod#rate-limiting-resource-allocation--abuse-prevention).
## Clean up anonymous users
Supabase doesn't delete anonymous users automatically. To delete them, run SQL like this:
```sql
-- deletes anonymous users created more than 30 days ago
delete from auth.users
where is_anonymous is true and created_at < now() - interval '30 days';
```
## When to use anonymous sign-ins
Use anonymous sign-ins to build:
- E-commerce applications, such as shopping carts before checkout
- Full-feature demos without collecting personal information
- Temporary or throwaway accounts
## Related resources
To read more about anonymous users, see these pages:
- [Convert an anonymous user](/docs/guides/auth/auth-anonymous/convert): link an email, phone, or OAuth identity to a guest.
- [Restrict anonymous user access](/docs/guides/auth/auth-anonymous/access-control): tell anonymous users apart in RLS policies.
- [Supabase JS Client](https://github.com/supabase/supabase-js): source and issues for the JavaScript SDK.
- [Supabase Flutter Client](https://github.com/supabase/supabase-flutter): source and issues for the Flutter SDK.
- [Supabase Kotlin Client](https://github.com/supabase-community/supabase-kt): source and issues for the Kotlin SDK.