Hey folks I have a trigger function ``` CREATE or...
# sql
j
Hey folks I have a trigger function
Copy code
CREATE or REPLACE function auth.update_token() RETURNS TRIGGER AS $$
  DECLARE
    alias text;
  BEGIN
    SELECT "public"."orgs".alias into alias from "public"."orgs" WHERE id = new.org_id;
    UPDATE users SET raw_app_meta_data = jsonb_set(raw_app_meta_data, ARRAY['roles', NEW.org_id::text], to_jsonb(NEW.roles)) WHERE id = NEW.user_id;
    IF trim(alias) <> '' THEN
      UPDATE users SET raw_app_meta_data = jsonb_set(raw_app_meta_data, ARRAY['roles', alias], to_jsonb(NEW.roles)) WHERE id = NEW.user_id;
    END IF;
    RETURN NEW;
  END;
$$ language plpgsql;
And a trigger:
Copy code
CREATE TRIGGER "Update token with allowed orgs" AFTER INSERT OR UPDATE
ON "public"."users_orgs"
FOR EACH ROW EXECUTE PROCEDURE auth.update_token();
But the trigger doesn't seem to be running the updates 🤷‍♂️
@User is it possible there's some sort of RLS in the auth schema making the update silently fail?