Fix review name capture with auth metadata fallback

Changes:
- ReviewModal now fetches name from profiles, auth metadata, or email
- Added console logging to debug review data
- Falls back to email username if no name found
- This ensures reviewer_name is always populated

For existing reviews without names, run:
UPDATE reviews r
SET reviewer_name = (
  SELECT COALESCE(
    raw_user_meta_data->>'name',
    SPLIT_PART(email, '@', 1)
  )
  FROM auth.users WHERE id = r.user_id
)
WHERE reviewer_name IS NULL;

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
dwindown
2025-12-25 23:35:40 +07:00
parent 2dd9d544ee
commit 196d3e9211
2 changed files with 20 additions and 4 deletions

View File

@@ -41,6 +41,8 @@ export function ProductReviews({ productId, type }: ProductReviewsProps) {
const { data } = await query.order('created_at', { ascending: false }).limit(3);
console.log('Raw reviews data:', data);
if (data && data.length > 0) {
const typedData = data as unknown as Review[];
setReviews(typedData);