Skip to content

Refactor Error Handling and Imports in Authentication Logic #84

@0010aor

Description

@0010aor

Description

Improve the authentication logic in the frontend by standardizing error handling and updating import paths for consistency and maintainability.

Current Behavior

  • The useAuth hook currently handles errors with a verbose and inconsistent pattern:
    err instanceof AxiosError
      ? err.message
      : 'body' in err && typeof err.body === 'object' && err.body
        ? String(err.body.detail) || ...
        : ...
  • The handleError utility in utils.ts is not reused in useAuth, leading to duplicated error handling logic.
  • Import paths for shared components (e.g., PasswordInput) in login.tsx and signup.tsx use relative imports instead of the @ alias (e.g., import PasswordInput from '@/components/commonUI/PasswordInput').
  • The useAuthContext.tsx file is located in the hooks folder, but it represents a context provider and hook, which would be more appropriately placed in a context directory.

Expected Behavior

  • Refactor error handling in useAuth to use a shared utility (e.g., refactor and reuse handleError from utils.ts), ensuring consistent and clear error messages for authentication flows.
  • Update all relevant imports in login.tsx and signup.tsx to use the @ alias for shared components, following the project's import conventions.
  • Move useAuthContext.tsx from the hooks folder to a new or existing context folder, and update all imports accordingly.
  • Consolidate the utils folder and utils.ts file into a single, well-organized location to avoid confusion and duplication. All utility functions should be imported from this unified module.
  • Ensure that error messages are user-friendly, translated, and displayed via toast notifications or inline feedback as appropriate.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions