-- 为商品评价提供最小公开用户资料视图，避免客户端直接访问 auth.users 或整表 ak_users。

create or replace view public.ak_user_public_profiles as
select
  id,
  coalesce(nullif(username, ''), '匿名用户') as username,
  coalesce(avatar_url, '') as avatar_url
from public.ak_users;

comment on view public.ak_user_public_profiles is '商品评价等前台展示使用的最小公开用户资料视图';

grant select on public.ak_user_public_profiles to anon;
grant select on public.ak_user_public_profiles to authenticated;
grant select on public.ak_user_public_profiles to service_role;