Refactor useAuth hooks for improved type safety, error handling, and compliance with auto-generated API client

- Migrated `useAuth` hooks to use functions from auto-generated API client for improved maintainability and OpenAPI compliance.
- Replaced manual API calls with SDK functions (`login`, `register`, `logout`, etc.) and added error type guards for runtime safety (`isTokenWithUser`, `isSuccessResponse`).
- Enhanced hooks with better error logging, optional success callbacks, and stricter type annotations.
- Refactored `Logout` and `LogoutAll` mutations to handle missing tokens gracefully and clear local state on server failure.
- Added tests for API type guards and updated functionality of hooks to validate proper behaviors.
- Removed legacy `client-config.ts` to align with new API client utilization.
- Improved inline documentation for hooks with detailed descriptions and usage guidance.
This commit is contained in:
Felipe Cardoso
2025-11-01 04:25:44 +01:00
parent 3ad48843e4
commit ea544ecbac
12 changed files with 2212 additions and 282 deletions

View File

@@ -22,8 +22,6 @@ const customJestConfig = {
'!src/**/*.stories.{js,jsx,ts,tsx}',
'!src/**/__tests__/**',
'!src/lib/api/generated/**', // Auto-generated API client - do not test
'!src/lib/api/client.ts', // TODO: Replace with generated client + thin interceptor wrapper
'!src/lib/api/errors.ts', // TODO: Remove - error parsing should be in generated client
'!src/**/*.old.{js,jsx,ts,tsx}', // Old implementation files
'!src/components/ui/**', // shadcn/ui components - third-party, no need to test
'!src/app/**', // Next.js app directory - layout/page files (test in E2E)