- Replaced imports in VerifyEmailPage.tsx (verifyEmail, resendVerificationEmail → authApi.verifyEmail, authApi.resendVerification) - Replaced imports in useUsernameAvailability.ts (checkUsernameAvailability → authApi.checkUsername with response.available extraction) - Replaced imports in usePasswordReset.ts (requestPasswordReset, resetPassword → authApi.requestPasswordReset, authApi.resetPassword) - Replaced imports in RegisterPage.tsx (resendVerificationEmail → authApi.resendVerification) - All function calls updated to use authApi methods with proper request object wrapping - Test files still use direct imports (acceptable - tests can use implementation details) - AuthContext.tsx uses services/authService (legacy service, separate from features/auth/services/authService) - No TypeScript errors related to authApi - Action 6.1.1.8 complete
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { useState } from 'react';
|
|
import { authApi } from '@/services/api/auth';
|
|
import type { ForgotPasswordFormData, ResetPasswordFormData } from '../types';
|
|
|
|
export function usePasswordReset() {
|
|
const [loading, setLoading] = useState(false);
|
|
const [error, setError] = useState<Error | null>(null);
|
|
const [success, setSuccess] = useState(false);
|
|
|
|
const handleRequestReset = async (data: ForgotPasswordFormData) => {
|
|
try {
|
|
setLoading(true);
|
|
setError(null);
|
|
setSuccess(false);
|
|
await requestPasswordReset(data);
|
|
setSuccess(true);
|
|
} catch (err) {
|
|
setError(err as Error);
|
|
setSuccess(false);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
const handleReset = async (data: ResetPasswordFormData) => {
|
|
try {
|
|
setLoading(true);
|
|
setError(null);
|
|
setSuccess(false);
|
|
await authApi.resetPassword(data);
|
|
setSuccess(true);
|
|
} catch (err) {
|
|
setError(err as Error);
|
|
setSuccess(false);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
return {
|
|
handleRequestReset,
|
|
handleReset,
|
|
loading,
|
|
error,
|
|
success,
|
|
};
|
|
}
|