Skip to content

Commit

Permalink
Login logout (#56)
Browse files Browse the repository at this point in the history
* Add. 디폴트 페이지 변경

* Del. 디폴트 페이지 비밀번호 찾기 삭제

* Del. 임시 주석 해제

* Upt. 사용자 데이터 수정

* Upt. 회원 탈퇴 로직 변경

* Upt. 탈퇴 로직 수정

* Upt. useState async fix
  • Loading branch information
jee-eun-k authored Jul 6, 2024
1 parent 52d6ac7 commit 9a6788f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ export const addUser = async (request: UserData) => {
* @param request: UserData
* @returns response
*/
export const deleteUser = async (request: UserData) => {
export const deleteUser = async (authProviderType: AuthProviderType) => {
const response = await callAPI({
url: `/api/v1/auth/withdrawal/${request.authProviderType}`,
url: `/api/v1/auth/withdrawal/${authProviderType}`,
method: 'POST',
});
return response as CommonResponse;
Expand Down
53 changes: 31 additions & 22 deletions src/pages/auth/common/VerifyCode.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Button, InputAdornment, Typography } from '@mui/material';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react';
import Countdown from 'react-countdown';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';

Expand Down Expand Up @@ -30,6 +30,12 @@ const VerifyCode = (props: any) => {
const signUpData = useRecoilValue(signUpDataState);
const [code, setCode] = useState('');

const refValue = useRef('');

useEffect(() => {
refValue.current = code;
}, [code]);

const itemArray: InputItemType[] = [
{
name: '이메일 인증 코드',
Expand Down Expand Up @@ -99,7 +105,7 @@ const VerifyCode = (props: any) => {
) => {
const value = event.target.value;
if (value.length) {
setCode(value);
setCode(() => value);
setIsNextButtonDisabled(false);
setNextButtonProps({
...nextButtonProps,
Expand All @@ -110,6 +116,27 @@ const VerifyCode = (props: any) => {
},
];

const getCodeVerified = async () => {
await verifyCode({
authenticationRequestId: refValue.current,
authenticationNumber: code,
})
.then((response) => {
if (response.status === 'SUCCESS') {
setCurrentStepIndex(currentStepIndex + 1);
props.handleNextButton();
} else {
let newAttemptCount = verificationAttemptCount + 1;
setVerificationAttemptCount(newAttemptCount);
setHelper(
`인증코드가 일치하지 않습니다. 다시 한번 확인 후 입력해주세요. (${newAttemptCount} / 5 회)`,
);
setIsHelperError(() => true);
}
})
.catch();
};

useEffect(() => {
setInstruction('인증코드를 입력해주세요.');
setNextButtonProps({
Expand All @@ -133,25 +160,7 @@ const VerifyCode = (props: any) => {
});
return true;
}

await verifyCode({
authenticationRequestId: requestId,
authenticationNumber: code,
})
.then((response) => {
if (response.status === 'SUCCESS') {
setCurrentStepIndex(currentStepIndex + 1);
props.handleNextButton();
} else {
let newAttemptCount = verificationAttemptCount + 1;
setVerificationAttemptCount(newAttemptCount);
setHelper(
`인증코드가 일치하지 않습니다. 다시 한번 확인 후 입력해주세요. (${newAttemptCount} / 5 회)`,
);
setIsHelperError(() => true);
}
})
.catch();
getCodeVerified();
},
isDisabled: true,
});
Expand All @@ -166,7 +175,7 @@ const VerifyCode = (props: any) => {
isHelperError={isHelperError}
value={code}
/>
<Box sx={{ position: 'relative', top: '15%' }}>
<Box sx={{ position: 'relative', top: '20%' }}>
<Typography
sx={{
fontSize: '11px',
Expand Down

0 comments on commit 9a6788f

Please sign in to comment.