ALTER TABLE public.users

    ADD COLUMN IF NOT EXISTS public_key JSONB;


-- Function to update user's public key

CREATE
OR REPLACE FUNCTION public.update_user_public_key(

    new_public_key JSONB

) RETURNS boolean AS $$

BEGIN

UPDATE public.users

SET public_key = new_public_key

WHERE uuid = auth.uid();

RETURN
FOUND;

END;

$$
LANGUAGE plpgsql SECURITY DEFINER;



GRANT EXECUTE ON FUNCTION public.update_user_public_key TO authenticated;