Skip to content

Conversation

@mung96
Copy link

@mung96 mung96 commented Mar 14, 2024

SSAFE 4차 MISSION: 타입스크립트와 API를 이용한 회원가입&로그인

2주차 구현 내용

1️⃣ [Protected Router 적용]

Protected Router 코드

2️⃣ [회원가입 Input에 reducer적용]

Reducer 코드

3️⃣ [로그인 Input에 커스텀훅 적용(useInput)

커스텀훅 코드

ProtectedRouter 작동 영상

  • 로그인 없이 마이페이지 접속하면 => 로그인 페이지로 이동 -> 로그인시 바로 마이페이지 접속
2024-03-14.10.16.36.mov

✏️ 파일 구조

Folder File Description
components Header 모든 페이지 상단에 등장하는 헤더
SignUpForm 회원가입 입력유효성 검사를 담당하는 컴포넌트
LoginForm 로그인 기능을 담당하는 컴포넌트
common/Button 회원가입, 로그인 페이지에 등장하는 버튼 컴포넌트
pages MainPage 첫 화면 페이지의 UI
SignUpPage 회원가입 페이지의 UI
LoginPage 로그인 페이지의 UI
apis AuthApi 회원가입과 로그인 Api 호출 기능
utils validator 이메일과 비밀번호 유효성검사 정규식

시도했지만 실패

커스텀훅을 다른 곳에서도 사용

환경변수로 baseURL을 설정

마이페이지를 로그인 시에만 보이도록

mung96 added 30 commits March 4, 2024 14:20
feat: 타입스크립트로 전환 + 이전파일 이동
타입스크립트 전환
로그인 페이지 UI구현
로그인 기능 리팩터링
-버튼 가운데 정렬
main 브랜치에 merge
메인 브랜치 병합
테스트시 에러메세지 alert
Copy link
Member

@kwakseongjae kwakseongjae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

커스텀훅 시도 너무 좋았다.
왜 잘 해 ??
나 무서워 ,,
합격 !! 😎✌

Comment on lines +19 to +22
{/*로그인 유저만 접근가능 */}
<Route element={<ProtectedRouter />}>
<Route path="/mypage" element={<MyPage />} />
</Route>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시도 조씁니다 👍👍

import axios from "axios";

const AuthApi = axios.create({
baseURL: "http://localhost:8000/auth",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

막히면 레퍼런스 물어봐 !
생각보다 적용하기 쉬워 !
https://i-ten.tistory.com/256

@@ -0,0 +1,23 @@
import styled, { css } from "styled-components";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

css는 어디서 쓰였나요 ?


const [errorMsg, decideErrorMsg] = useErrorMsg();
const location = useLocation();
const from = location?.state?.redirectFrom?.pathname || "/";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 레퍼런스 찾았나보네 👍👍
자주 사용되니까 꼭 외워둬 !

Comment on lines +45 to +50
<label htmlFor="email">이메일</label>
<input
name="email"
placeholder="ssafe11@gmail.com"
onChange={handleEmailChange}
/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id 선택자 추가하셔야지 !!

Comment on lines +179 to +181
<Button active={isActive} onClick={handleBtnClick}>
회원가입
</Button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onClick, handleSubmit, handleSignup 등의 좋은 변수명도 많습니당 :)
handleBtnClick은 저는 잘 안쓸거같네용

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개멋지다... 미쳤다... 👍👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뭔데 이거 !!!
잘짠거같은데 왜 안썼어 ??

Comment on lines +99 to +107
<Link to="/signup">
<Button>회원가입</Button>
</Link>
<Link to="/login">
<Button>로그인</Button>
</Link>
<Link to="/mypage">
<Button>마이페이지</Button>
</Link>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +9 to +13
{accessToken ? (
<Outlet />
) : (
<Navigate to="/login" state={{ redirectFrom: currentLocation }} />
)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시도는 좋은데 조금 더 컨벤션을 찾아보면 좋을거같다는 생각 !
제로 베이스로 떠올린거면 꽤 준수하넹
if문이랑 return이 있는 레퍼런스 한번 찾아봐 !
보통은 그렇게 많이 작업해 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants