Skip to content

Add badge awarding logic — currently badges can only be assigned via seed #191

@3m1n3nc3

Description

@3m1n3nc3

Description

The UserBadge join table, Badge model, and AchievementsDialog component exist and render correctly. However, there is no server-side logic to award badges based on user activity. The only way a user can have badges is if they are manually seeded. The context AWARD_BADGE action updates memory only.

More info

  • Create a checkAndAwardBadges(userId: string) server-side function that evaluates eligibility rules and creates UserBadge records.
  • This function should be called from API endpoints after relevant actions (post created, entry won, etc.).
  • Example rules:
    • "First Giveaway" badge: awarded when a user creates their first giveaway.
    • "Generous Heart" badge: awarded after contributing to 10 help requests.
    • "Community Builder" badge: awarded when the user reaches 100 followers.
  • The /api/auth/me endpoint (and /api/users/[id]) already return badges with awardedAt, so the UI will reflect new badges automatically once the awarding logic exists.
  • Remove the in-memory checkAndAwardBadges call from app-context.tsx once the server-side version is in place.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions