Skip to content

Conversation

@airowe
Copy link

@airowe airowe commented May 13, 2025

Pull Request: Authentication Context Refactor, DRY Improvements, and Test Integration

Summary

This PR refactors the authentication logic and context to be fully DRY, modular, and testable. It also aligns the implementation with the project prompt requirements.


Key Changes

  • Authentication Context Refactor

    • Centralized all token storage logic in storage.ts.
    • All reducer logic and types are now in authReducer.ts.
    • AuthContext and AuthProvider only use helpers and reducer, with no duplicated logic.
    • Tokens (accessToken, refreshToken) are persisted in AsyncStorage to simulate server Set-Cookie headers, as HttpOnly cookies are not available in React Native.
    • The user object is kept in memory only, not persisted.
  • Prompt Compliance

    • Simulates a POST to /auth/login and uses a hardcoded mock user response.
  • Testing

    • Added integration tests for the login flow in LoginScreen, including error handling and successful login.
    • Added unit tests for AuthContext and reducer logic.
    • Ensured all async timers are cleaned up in tests to prevent leaks and warnings.
    • Suppressed or documented unavoidable act warnings due to async effects in React Testing Library.
  • Project Structure

    • All context, reducer, and utility code is organized under src.
    • No business logic or storage code is duplicated across files.

Notes

  • The .expo folder is not committed and remains in .gitignore as per Expo recommendations.
  • All changes are documented in code comments for clarity.
  • The authentication flow is now ready for extension to real API integration or web cookie handling if needed in the future.

This PR improves maintainability, testability, and clarity of the authentication system, and ensures full alignment with the project requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant