-- Allow anyone to read organization basic info when referenced by a valid invite. -- This is needed so the invite page can display the org name to non-members. CREATE POLICY "Anyone can view org via valid invite" ON public.organizations FOR SELECT USING ( EXISTS ( SELECT 1 FROM public.org_invites oi WHERE oi.org_id = organizations.id AND oi.accepted_at IS NULL AND (oi.expires_at IS NULL OR oi.expires_at > now()) ) );