Skip to content

Commit

Permalink
Merge pull request #39 from junhyeon0218/fix/error
Browse files Browse the repository at this point in the history
🐛 Fix: build시 error해결
  • Loading branch information
junhyeon0218 authored Sep 7, 2024
2 parents ea65561 + 8ed0652 commit d91e547
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/api/apis/auth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosError } from 'axios';
import { baseInstance } from '../util/instance';
import { setCookie } from '../../utils/cookie';
import { setItem } from '../../utils/storage';
Expand All @@ -8,6 +9,11 @@ interface SignupData {
nickname: string;
}

// AxiosError인지 확인하는 타입 가드 함수
const isAxiosError = (error: unknown): error is AxiosError => {
return (error as AxiosError).isAxiosError !== undefined;
};

export const signupAPI = async (data: SignupData) => {
try {
const response = await baseInstance.post<void>('/api/users/signup/', data);
Expand Down Expand Up @@ -42,7 +48,7 @@ export const checkEmailAPI = async (email: string) => {
const response = await baseInstance.post('/api/users/checkEmail/', { email: email });
return response.status === 200; // 중복이 아니면 true 반환
} catch (error) {
if (error.response && error.response.status === 400) {
if (isAxiosError(error) && error.response && error.response.status === 400) {
return false; // 중복이면 false 반환
}
console.error('Failed to check email:', error); // 다른 에러 로그 출력
Expand All @@ -56,7 +62,7 @@ export const checkNicknameAPI = async (nickname: string) => {
console.log(response);
return response.status === 200; // 성공 시 boolean 반환
} catch (error) {
if (error.response && error.response.status === 400) {
if (isAxiosError(error) && error.response && error.response.status === 400) {
return false; // 중복이면 false 반환
}
console.error('Failed to check nickname:', error); // 다른 에러 로그 출력
Expand Down
7 changes: 6 additions & 1 deletion src/pages/auth/Signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import Button from '../../components/common/Button';
import { Link, useNavigate } from 'react-router-dom';
import { signinAPI } from '../../api/apis/auth';
import { getCookie } from '../../utils/cookie';
import { AxiosError } from 'axios';

interface InputProps {
email: string;
password: string;
}

const isAxiosError = (error: unknown): error is AxiosError => {
return (error as AxiosError).isAxiosError !== undefined;
};

const Signin = () => {
const {
register,
Expand All @@ -29,7 +34,7 @@ const Signin = () => {
navigate('/');
console.log('Signin successful');
} catch (error) {
if (error.response && error.response.status === 400) {
if (isAxiosError(error) && error.response && error.response.status === 400) {
setErrorMessage('이메일 또는 비밀번호가 잘못되었습니다.');
} else {
setErrorMessage('로그인 중 오류가 발생했습니다. 다시 시도해 주세요.');
Expand Down
1 change: 1 addition & 0 deletions src/pages/fti/FtiTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const FtiTest = () => {
};

useEffect(() => {
console.log(results);
getQuestion();
}, []);

Expand Down

0 comments on commit d91e547

Please sign in to comment.