Skip to content

fix: resolve volunteer signup issue

Aravind swamy Majjuri requested to merge volunteer-signup-qrcode into develop

Overview

This MR fixes incorrect volunteer signup state persistence across different camps by introducing camp-specific tracking in localStorage.

Previously, signup status from one camp was reused globally, causing users to be incorrectly redirected (e.g., to the QR page) when accessing a different camp.


What does this MR do and why?

The issue occurred because volunteer signup state was stored without associating it with a specific camp_id. As a result:

  • If a user signed up for one camp
  • Then opened another camp
  • The app incorrectly assumed they were already signed up

Solution

  • Introduced camp-specific caching using camp_id
  • Ensured cached data is reused only when it matches the current camp
  • Cleared stale data when switching camps or logging out

This guarantees correct behavior across multiple camps and avoids false redirects.


Changes Made

  • src/lib/api.ts

    • Added camp-specific localStorage keys:

      • volunteer_already_signed_up
      • volunteer_signed_up_camp_id
    • Updated getVolunteerCampSignupStatus():

      • Stores camp_id when signup is true
      • Validates cached signup state against current camp_id
      • Clears stale cache if camp mismatch is detected
    • Prevents previous camp signup state from affecting new camps

  • src/contexts/AuthContext.tsx

    • Updated clearAuthToken():

      • Removes volunteer_signed_up_camp_id from localStorage
    • Ensures signup state is reset on logout


Technical Details

Root Cause

  • Signup state was stored globally without any reference to camp_id
  • This caused stale state reuse across different camps

Fix Approach

  • Introduced camp-scoped caching

  • Added validation logic:

    • Compare stored camp_id with current camp
    • Use cache only if they match
  • Cleanup strategy:

    • Remove stale cache when mismatch occurs
    • Clear cache on logout

Trade-offs

  • Slight increase in localStorage usage
  • Added conditional logic, but improves correctness and UX significantly

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • New feature
  • 💥 Breaking change
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • ️ Refactor
  • Performance improvement
  • 🧪 Test update
  • 🔧 Configuration change
  • 🚨 Security fix

Related Issues / References

  • Fixes incorrect volunteer signup state reuse across camps

Screenshots or Screen Recordings

Before:

image

After :

image


How to Set Up and Validate Locally

  1. Pull this branch:

    git checkout <volunteer-signup-qrcode>
  2. Install dependencies:

    npm install
  3. Run the app:

    npm run dev
  4. Test scenarios:

    • Signup as volunteer in Camp A

    • Open Camp B

    • Verify:

      • User is NOT redirected to QR page
      • Fresh signup state is shown
  5. Logout and verify:

    • Signup state is cleared
    • No stale data persists

Testing Done

  • Manual testing completed
  • Unit tests added/updated

Code Quality Checklist

Code Standards

  • Code follows project conventions
  • No console logs
  • No unused variables
  • No duplicate code
  • ESLint & Prettier pass

React Best Practices

  • Proper hook usage
  • Clean state management
  • No unnecessary re-renders

API & Data Fetching

  • Proper state handling
  • Error cases considered

Error Handling

  • Stale state handled gracefully
  • No incorrect redirects

Documentation

  • README.md updated
  • .env.example updated

Known Limitations / Technical Debt

  • Signup state still relies on localStorage
  • No expiration mechanism for cached data (can be improved later)

Additional Notes

  • This fix improves multi-camp user experience
  • Prevents incorrect navigation flows (especially QR page redirection)
  • Future improvement: move caching to server or add TTL

Edited by Aravind swamy Majjuri

Merge request reports

Loading