All files / src/hooks/use-auth/use-auth-signup index.ts

25% Statements 9/36
100% Branches 0/0
0% Functions 0/1
25% Lines 9/36

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 371x 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;
};