Demo, all content is generated
Question

Deleted a user in Supabase but they're still logged in and can use the app

Open · 563 views · asked by connor_b · edited

Had to kick out a user who was harassing others. Deleted him in the Supabase Auth dashboard. 20 minutes later he's still posting. How? He doesn't exist anymore.

What I’ve tried

Deleted him twice (second time it said user not found). Banned his email in my own blocklist table, but he's already logged in so it doesn't check.

Comment
How long ago did you delete him? Access tokens live an hour by default. hannah_reyes · edited
about 25 min connor_b · edited

2 answers

hannah_reyes · edited

His browser still holds a valid access token (a signed JWT, valid up to 1 hour by default). RLS checks auth.uid() from that token without asking the auth server whether the user still exists. So until it expires, requests work. The refresh will fail, then he's out.

To cut it off immediately:

  • In RLS on the tables that matter, also require the user to have a profile row (which you delete, or mark banned):
using (exists (select 1 from profiles p where p.id = auth.uid() and not p.banned))

That's checked on every query, so a ban is instant.

  • For the future, use the ban option (ban_duration via the admin API) instead of deleting. You keep his data for reference and he can't sign up again with the same account.
Comment
He's gone now (token expired I guess). Adding the banned column for next time. connor_b · edited
And in server code prefer getUser() over getSession(). getUser asks the auth server, so a deleted user fails there right away. jb_supa · edited
amir_h · edited

You can also shorten the access token lifetime in the Auth settings (JWT expiry). Default is 3600 seconds; 10-15 minutes is reasonable if you need faster revocation. Costs a few more refresh calls, nothing noticeable.

Comment