ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseโ€ข4y agoโ€ข
7 replies
Thenlie

onAuthStateChange not triggered on account deletion

I have created a function to allow users to delete their account.
create or replace function delete_user()
  returns void
LANGUAGE SQL SECURITY DEFINER as $$
   delete from auth.users where id = auth.uid();
$$;
create or replace function delete_user()
  returns void
LANGUAGE SQL SECURITY DEFINER as $$
   delete from auth.users where id = auth.uid();
$$;

This works just fine to delete the account. I now want to perform an action in my code when that happens. I want this action to trigger within the onAuthStateChange. The problem is the 'USER_DELETE' event never gets triggered. I am running the function via rpc, so not sure if that is causing the problem.
const { data } = SUPABASE.auth.onAuthStateChange((_event, session) => {
    switch (_event) {
    case 'SIGNED_IN':
        setSession(session as Session);
        profileSetter(session as Session);
                navigate('/dashboard');
        break;
    case 'SIGNED_OUT':
        setSession(null);
        setProfile(null);
                navigate('/');
        break;
    case 'TOKEN_REFRESHED':
        setSession(session as Session);
        break;
    case 'USER_UPDATED':
        setSession(session as Session);
        profileSetter(session as Session);
        break;
    case 'USER_DELETED':
                console.log('hit'); // never runs
        setSession(null);
        setProfile(null);
        break;
    }
});
const { data } = SUPABASE.auth.onAuthStateChange((_event, session) => {
    switch (_event) {
    case 'SIGNED_IN':
        setSession(session as Session);
        profileSetter(session as Session);
                navigate('/dashboard');
        break;
    case 'SIGNED_OUT':
        setSession(null);
        setProfile(null);
                navigate('/');
        break;
    case 'TOKEN_REFRESHED':
        setSession(session as Session);
        break;
    case 'USER_UPDATED':
        setSession(session as Session);
        profileSetter(session as Session);
        break;
    case 'USER_DELETED':
                console.log('hit'); // never runs
        setSession(null);
        setProfile(null);
        break;
    }
});

Let me know if I can provide any other information!
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Account Deletion
SupabaseSSupabase / help-and-questions
3y ago
Account Deletion
SupabaseSSupabase / help-and-questions
4y ago
{Solved} Account Deletion
SupabaseSSupabase / help-and-questions
4y ago
onAuthStateChange not triggered when using server-side signIn/signOut in Next.js with Supabase
SupabaseSSupabase / help-and-questions
7mo ago