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

@@ -1,10 +1,22 @@
// Learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom'
import 'whatwg-fetch'; // Polyfill fetch API for MSW
import { Crypto } from '@peculiar/webcrypto';
// Mock window object
global.window = global.window || {};
// Mock BroadcastChannel for MSW
global.BroadcastChannel = class BroadcastChannel {
constructor(name) {
this.name = name;
}
postMessage() {}
close() {}
addEventListener() {}
removeEventListener() {}
};
// Use real Web Crypto API polyfill for Node environment
const cryptoPolyfill = new Crypto();