Skip to content

Commit

Permalink
Merge pull request #323 from BCSDLab/feat/#322/email-issue
Browse files Browse the repository at this point in the history
[코인 오너] 이메일 인증 관련 이슈 해결
  • Loading branch information
chaeseungyun authored May 9, 2024
2 parents bdb3579 + 07e3307 commit e202873
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
23 changes: 16 additions & 7 deletions src/page/Auth/Signup/component/UserEmail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ErrorMessage from 'page/Auth/Signup/component/ErrorMessage';
import useRegisterInfo from 'store/registerStore';
import useTimer from 'page/Auth/Signup/hooks/useTimer';
import { useEffect } from 'react';
import { isKoinError } from '@bcsdlab/koin';
import styles from './UserEmail.module.scss';

export default function UserEmail() {
Expand All @@ -16,22 +17,29 @@ export default function UserEmail() {
emailHandleSubmit, errors, emailDuplicateRegister, watch,
} = useValidateEmail();
const {
isOpen, onSubmit: emailSubmit, email, refetch, errorMessage,
} = useAuthCheck(userData.email ? userData.email : '', isMobile);
isOpen, onSubmit: emailSubmit, email, refetch, errorMessage, status,
} = useAuthCheck(userData.email ? userData.email : '', isMobile); // 회원가입 인증번호 전송
const {
verificationCode,
codeInput, errorMessage: verificateError, status,
} = useVerification(email);
codeInput, errorMessage: verificateError,
} = useVerification(email); // 사장님 이메일 인증번호 확인
const { getTime, startTimer, stopTimer } = useTimer(300);
const reSubmit = () => {
const reSubmit = async () => {
const { error, isError } = await refetch();
if (isError) {
if (isKoinError(error)) {
if (error.status === 409) {
return; // 재발송 요청이 너무 빠르면 시간을 초기화하지 않고 에러를 보여줌
}
}
}
startTimer();
refetch();
};
useEffect(() => {
if (userData.isAuthentication) {
stopTimer();
}
}, [stopTimer, userData.isAuthentication]);
}, [stopTimer, userData.isAuthentication, verificateError]);
useEffect(() => {
if (status === 'success') {
startTimer();
Expand Down Expand Up @@ -89,6 +97,7 @@ export default function UserEmail() {
<input className={styles.input} type="password" pattern="\d*" maxLength={6} placeholder="인증번호 입력" ref={codeInput} />
</div>
{verificateError && <ErrorMessage message={verificateError} />}
{errorMessage && <ErrorMessage message={errorMessage} />}
<span className={styles['email-check__alert']}>{`* 제한시간 ${getTime()}`}</span>
</div>
<div className={styles.buttons}>
Expand Down
5 changes: 3 additions & 2 deletions src/page/Auth/Signup/hooks/useAuthCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { useGenerateAuthCode } from 'query/register';
import { useEffect, useState } from 'react';
import { SubmitHandler } from 'react-hook-form';
import { User } from 'page/Auth/Signup/types/User';
import { AxiosError } from 'axios';

export default function useAuthCheck(userEmail:string, isMobile:boolean) {
const [email, setEmail] = useState('');
const [isOpen, setOpen] = useState(false);
const {
status, refetch, isError, error,
} = useGenerateAuthCode(email);
const errorMessage = status === 'error' ? Object(error).message : null;
const errorMessage = isError ? (error as AxiosError).message : null;
const onSubmit:SubmitHandler<User> = (data) => {
setEmail(() => (data.email ? data.email : ''));
};
Expand All @@ -33,6 +34,6 @@ export default function useAuthCheck(userEmail:string, isMobile:boolean) {
}, [status, isError, error]);

return {
onSubmit, isOpen, errorMessage, email, refetch, status,
onSubmit, isOpen, errorMessage, email, refetch, status, error,
};
}
4 changes: 0 additions & 4 deletions src/page/Auth/Signup/hooks/useTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ export default function useTimer(targetTime:number) {
}
}, [time]);

useEffect(() => {
startTimer();
}, [startTimer]);

const getTime = () => getTimeString(time);

return { getTime, startTimer, stopTimer };
Expand Down

0 comments on commit e202873

Please sign in to comment.