Skip to content

Commit

Permalink
Fix/#140: 중복된 닉네임 입력 시 300ms 간격으로 중복 검사를 반복하던 오류 수정 (#141)
Browse files Browse the repository at this point in the history
* fix: 중복된 닉네임 입력 시 300ms 간격으로 중복 검사를 반복하던 오류 수정

추가로 입력한 닉네임이 두 글자 미만인 경우 요청을 보내지 않도록 합니다. (서버 비용 절감)

* refactor: 네이버 오어쓰 로그인 기능 개발 전까지 Alert로 대체
  • Loading branch information
semnil5202 authored Apr 29, 2024
1 parent b288ec8 commit 3914225
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/pages/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { useNavigate } from 'react-router-dom';

import SEOMeta from '../../components/SEOMeta/SEOMeta';
import { BASE_URL } from '../../constants';
import useAlert from '../../hooks/useAlert';

const REQUEST_URL = `${BASE_URL}/oauth/kakao`;

const Login = () => {
const navigate = useNavigate();
const openAlert = useAlert();

const onClickOauthKakao = () => {
window.location.href = REQUEST_URL;
Expand All @@ -32,7 +34,10 @@ const Login = () => {

<Spacer size={10} />

<ButtonWrapper>
{/* 네이버 로그인 기능 완료 시 수정 */}
<ButtonWrapper
onClick={() => openAlert({ content: '아직 준비 중인 기능입니다. 카카오로 로그인을 수행해 주세요.' })}
>
<LogoBox color="#03C75A">
<SVGLoginNaver />
</LogoBox>
Expand Down
7 changes: 4 additions & 3 deletions src/pages/SignUp/hooks/useCheckDuplicateNickname.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Dispatch, SetStateAction, useEffect, useRef } from 'react';

import { getCheckDuplicateNickname } from '../../../api';
import { getUserNickname } from '../../Feed/utils/getUserNickname';
import { FieldValue } from '../types';

interface Props {
Expand All @@ -9,11 +10,11 @@ interface Props {
}

const useCheckDuplicateNickname = ({ nickname, setFieldErrorValue }: Props) => {
const userInfo = JSON.parse(localStorage.getItem('user') ?? '{}');
const userNickname = getUserNickname();
const timerId = useRef<number | null>(null);

useEffect(() => {
if (userInfo.nickname === nickname) return;
if (userNickname === nickname || nickname.length < 2) return;

if (timerId.current) {
const timerIdCurrent = timerId.current;
Expand All @@ -32,7 +33,7 @@ const useCheckDuplicateNickname = ({ nickname, setFieldErrorValue }: Props) => {
}));
}
}, 300);
}, [userInfo, nickname, setFieldErrorValue]);
}, [userNickname, nickname, setFieldErrorValue]);
};

export default useCheckDuplicateNickname;

0 comments on commit 3914225

Please sign in to comment.