diff --git a/supabase/migrations/20251014183600_9391fdea-87b6-4a17-bf2a-d686782a4a38.sql b/supabase/migrations/20251014183600_9391fdea-87b6-4a17-bf2a-d686782a4a38.sql new file mode 100644 index 00000000..68077343 --- /dev/null +++ b/supabase/migrations/20251014183600_9391fdea-87b6-4a17-bf2a-d686782a4a38.sql @@ -0,0 +1,38 @@ +-- Fix type mismatch in get_my_sessions function +-- The refreshed_at column in auth.sessions is timestamp, not timestamptz +DROP FUNCTION IF EXISTS public.get_my_sessions(); + +CREATE OR REPLACE FUNCTION public.get_my_sessions() +RETURNS TABLE ( + id uuid, + created_at timestamptz, + updated_at timestamptz, + refreshed_at timestamp, + user_agent text, + ip inet, + not_after timestamptz, + aal auth.aal_level +) +SECURITY DEFINER +SET search_path = auth, public +LANGUAGE plpgsql +AS $$ +BEGIN + -- Only return sessions for the authenticated user + RETURN QUERY + SELECT + s.id, + s.created_at, + s.updated_at, + s.refreshed_at, + s.user_agent, + s.ip, + s.not_after, + s.aal + FROM auth.sessions s + WHERE s.user_id = auth.uid() + ORDER BY s.refreshed_at DESC NULLS LAST, s.created_at DESC; +END; +$$; + +GRANT EXECUTE ON FUNCTION public.get_my_sessions() TO authenticated; \ No newline at end of file