AthletiFi / athletifi-website

Official website for AthletiFi
https://www.athleti.fi
1 stars 5 forks source link

Implement Referral Invite Functionality and Enhance Authentication Flow #258

Closed HectorAgudelo closed 1 month ago

HectorAgudelo commented 1 month ago

This pull request introduces the referral invite functionality and makes several enhancements to the authentication flow in our Next.js application. The main changes include:

  1. Referral Invite:

    • Added support for preserving the invite_id during the OAuth flow with Google and Facebook.

    • Modified the userStore.ts file to use atomWithStorage from Jotai for persisting the invite_id in localStorage.

    • Updated the AuthClient component to access and update the inviteIdAtom using the useAtom hook.

    • Modified the useUserData hook to access the inviteIdAtom using the useAtomValue hook.

    • Updated the handlePostSignIn function to pass the inviteId from the Jotai state.

    • Implemented expiration mechanism for the invite_id in localStorage, with a default expiration time of 5 hours.

    • Added logic to remove the invite_id from localStorage when the user logs out.

  2. Authentication Flow:

    • Created a new register/page.tsx file to handle user registration.

    • Modified the login/page.tsx file to update the authentication layout.

    • Updated the AuthClient component to handle user registration and login flows.

    • Enhanced the useUserData hook to fetch user data whenever the amplify_id changes.

    • Improved error handling and user feedback during authentication processes.

  3. Backend Configuration:

    • Modified the amplify/backend/auth/athletifiAuth/cli-inputs.json file to update the authentication configuration in the Amplify backend.
  4. Code Optimization:

    • Refactored the useUserData hook to improve code readability and maintainability.

    • Optimized the logic for updating user data and notification preferences.

    • Fixed merge conflicts in the userStore.ts file.

These changes significantly enhance the authentication experience for users by introducing referral invite functionality and streamlining the registration and login processes. The referral invite feature allows users to join the platform through personalized invitation links, while the improved authentication flow provides a smooth and intuitive user experience.

Please review the code changes carefully, and let me know if you have any questions or suggestions for further improvements.