Files
thrilltrack-explorer/supabase/migrations/20251001160858_95431631-c4fa-471a-9c1f-7684bdf416d0.sql
2025-10-01 16:09:32 +00:00

22 lines
604 B
PL/PgSQL

-- Create a function to cancel pending email changes
-- This function runs with SECURITY DEFINER privileges to access auth.users table
CREATE OR REPLACE FUNCTION public.cancel_user_email_change(_user_id UUID)
RETURNS BOOLEAN
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = auth, public
AS $$
BEGIN
-- Clear all email change related fields in auth.users
UPDATE auth.users
SET
email_change = NULL,
email_change_sent_at = NULL,
email_change_confirm_status = 0,
email_change_token_current = NULL,
email_change_token_new = NULL
WHERE id = _user_id;
RETURN FOUND;
END;
$$;