-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_function.sql
More file actions
45 lines (39 loc) · 1.42 KB
/
Copy pathfix_function.sql
File metadata and controls
45 lines (39 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
-- ============================================
-- Fix: Recreate verify_admin_password function
-- Run this in Supabase SQL Editor if you get "function does not exist" error
-- ============================================
-- Step 1: Ensure pgcrypto extension is enabled
CREATE EXTENSION IF NOT EXISTS pgcrypto;
-- Step 2: Drop function if it exists (with different signatures)
DROP FUNCTION IF EXISTS public.verify_admin_password(TEXT);
DROP FUNCTION IF EXISTS verify_admin_password(TEXT);
-- Step 3: Recreate the function with proper extension access
CREATE OR REPLACE FUNCTION public.verify_admin_password(plain_password TEXT)
RETURNS TABLE(id UUID, name TEXT)
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
DECLARE
matched_admin RECORD;
BEGIN
-- Loop through all active admins and check password
FOR matched_admin IN
SELECT ap.id, ap.name, ap.password_hash
FROM public.admin_passwords ap
WHERE ap.is_active = true
LOOP
-- Use crypt function from pgcrypto extension
IF matched_admin.password_hash = crypt(plain_password, matched_admin.password_hash) THEN
id := matched_admin.id;
name := matched_admin.name;
RETURN NEXT;
EXIT;
END IF;
END LOOP;
RETURN;
END;
$$;
-- Step 4: Grant permissions
GRANT EXECUTE ON FUNCTION public.verify_admin_password(TEXT) TO anon, authenticated;
-- Step 5: Test the function (should return manan's record)
SELECT * FROM public.verify_admin_password('football');