Give visitors a real user id before they sign up, and keep their data when they do.
Turn on Anonymous sign-ins in Studio → Authentication → Sign-in methods, then:
JavaScript
const { data } = await stitchdb.auth.signInAnonymously()
console.log(data.user.id, data.user.is_anonymous) // trueAnonymous users get the authenticated role and an is_anonymous: true claim. Tell them apart in policies:
SQL
create policy "Only permanent users can post" on public.posts
as restrictive for insert to authenticated
with check ((auth.jwt() ->> 'is_anonymous')::boolean is false);#Convert to a permanent account
JavaScript
await stitchdb.auth.updateUser({ email: '[email protected]' }) // confirm the e-mail, then
await stitchdb.auth.updateUser({ password: 'a-strong-password' })
// or link an OAuth provider
await stitchdb.auth.linkIdentity({ provider: 'google' })The user id stays the same, so rows created while anonymous keep belonging to them.