auth icon indicating copy to clipboard operation
auth copied to clipboard

Signout fails after user account has been deleted

Open paule89123 opened this issue 4 months ago • 0 comments

Describe the bug

supabase.auth.signOut() fails if the user has been deleted. The error is AuthApiError: User from sub claim in JWT does not exist

To Reproduce

See code below (under "Additional context")

Expected behavior

supabase.auth.signOut() should clear the local cache if the user has been deleted.

System information

  • OS: iOS
  • Version of supabase-js: 2.25.0
  • Version of Node.js: 18.19.0

Additional context

My app needs to allow users to delete their accounts. In order to do this, I have created a database function that does the following:

` -- Get the user's ID and email address SELECT id, email INTO user_id, user_email FROM auth.users WHERE id = auth.uid();

-- Insert a record into the deleted_users table INSERT INTO public.deleted_users (id, email) VALUES (user_id, user_email);

-- Delete the user from the auth.users table DELETE FROM auth.users WHERE id = user_id;`

I call this from the client with:

await supabase.rpc('delete_user')

This successfully deletes the user from auth.users, and deletes their session and refresh token from the db as well. However, the user's session is still cached locally on the client (I'm using React Native/Expo). Thus, I need to log the user out locally. However, calling await supabase.auth.signOut() fails with the error:

AuthApiError: User from sub claim in JWT does not exist

paule89123 avatar Apr 06 '24 11:04 paule89123