Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { useRouter } from 'next/navigation';
import { AxiosError } from 'axios';
import { API } from '@/api';
import { SignupRequest } from '@/types/service/auth';
import { CommonErrorResponse } from '@/types/service/common';
export const useSignup = () => {
const router = useRouter();
const handleSignup = async (payload: SignupRequest, formApi: { reset: () => void }) => {
try {
const result = await API.authService.signup(payload);
// π μΆν μμ
console.log('signup success:', result);
formApi.reset();
router.push('/login');
} catch (error) {
const axiosError = error as AxiosError<CommonErrorResponse>;
const problem = axiosError.response?.data;
// π μλ¬ UI κ²°μ λλ©΄ λ³κ²½
if (problem) {
console.error('[SIGNUP ERROR]', problem.errorCode, problem.detail);
alert(problem.detail || 'νμκ°μ
μ μ€ν¨νμ΅λλ€.');
} else {
console.error(error);
alert('μ μ μλ μ€λ₯κ° λ°μνμ΅λλ€.');
}
}
};
return handleSignup;
};
|