Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[비밀번호 재설정] api 연결 & 처리 #60

Open
wants to merge 4 commits into
base: feature/login
Choose a base branch
from

Conversation

live-small
Copy link
Member

개요

  • 브랜치: subfeat/login/resetPassword
  • 실제 유저가 비밀번호 재설정을 하고자 할 때만 유저의 이메일로 재설정 메일을 통해 재설정 할 수 있음
  • 비밀번호 재설정 메일
    • 로그인: 이메일 인증했기에 유저의 이메일로 로그인 할 수 있음.
    • 비밀번호 재설정

작업사항

  • 비밀번호 재설정 클릭 시, url query의 code를 이용해 유효한 페이지인지 체크함
    • 비밀번호 재설정 메일을 통해서만 code를 받을 수 있고, code는 몇 분만 유효함.
    • 유효한 코드일 경우, 비밀번호 재설정 폼을 통해 비밀번호를 재설정하고, 로그인되어 home이 렌더링 됨.
  • 로그인 클릭 시, url query의 username과 code로 코드를 통한 로그인 api를 호출해 로그인되어 home이 렌더링 됨.

고민

  • method 리턴 타입이 여러개일 때, 어떻게 처리해서 이용하시나요?

    • 배경: query-string.parse의 리턴타입:string | (string | null) [] | null
    • string타입으로 바꿔, 이용하고 싶은데 어떻게 처리하는 게 좋을지 고민이 돼서 남깁니다.
      • as String으로 추론하기 ?
      • typeof value === “string”인지 체크하고 이용하기? 현재 이 방법으로 구현했는데, 그 값을 이용할 때마다 반복해서 체크해야하다보니..좋지 않은 거 같습니다.
  • 비밀번호 재설정버튼 클릭 시, url query의 code를 이용해 유효한 페이지인지 체크하는데요, 만료된 코드여서 유효하지 않은 페이지를 보여줘야할 때, 리덕스 상태값을 하나 만들어서 라우터를 변경하는 게 어떨까 생각했습니다.

    • 아래 사진은 실제 인스타그램에서 유효하지 않은 페이지일경우 보여주는 화면입니다. 링크가 잘못됐거나 페이지가 삭제됐을 때도 이 페이지를 이용하는 거 같은데, auth외에서 이 페이지를 이용할 경우가 없을까요?
    • 다른 곳에서도 이용할 수도 있을 거 같아서, 만들려는 상태값을 auth에서 관리해도 될까라는 생각이 들었습니다.

스크린샷 2022-05-15 오후 11 31 32

1) 백엔드에서 넘겨준 url에 code로 페이지 유효한지 체크 2) 비밀번호 재설정 버튼 클릭 시, api호출 후 로그인 시킴
Copy link
Member Author

@live-small live-small left a comment

Choose a reason for hiding this comment

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

pr에 적어놨던 부분을 표시해뒀습니다!

@@ -90,6 +96,16 @@ const authSlice = createSlice({
state.isLogin = true;
setAccessTokenInAxiosHeaders(action.payload);
})
.addCase(resetPassword.fulfilled, (state, action) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

resetPassword,fulfileed에도, signInUseCode.fulfiled에도 동일한 처리를 하게 되는데 리덕스 툴킷 내에서 재사용할 수 있는 방법을 혹시 아시나요?

Copy link
Collaborator

Choose a reason for hiding this comment

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

그러게요.. 뭔가 필요하긴 하겠는데 막상 방법이 떠오르지않네요

Copy link
Collaborator

Choose a reason for hiding this comment

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

찾아보니 addMatcherisAllOf 등을 사용하는 방법이 있다네요? 정확히 맞는지는 모르겠지만 한 번 확인해보세요!
스크린샷 2022-09-07 오후 5 06 44

Copy link
Member Author

Choose a reason for hiding this comment

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

오오 감사합니다. 한번 찾아볼게요!

@@ -90,6 +96,16 @@ const authSlice = createSlice({
state.isLogin = true;
setAccessTokenInAxiosHeaders(action.payload);
})
.addCase(resetPassword.fulfilled, (state, action) => {
state.isLoading = false;
Copy link
Member Author

Choose a reason for hiding this comment

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

isLoading값으로 로딩처리해주는 부분을 깜빡했네요. 추가하겠습니다!

src/components/Auth/ResetPassword/ResetPasswordForm.tsx Outdated Show resolved Hide resolved
state.errorMessage = `전에 사용한 적 없는 새로운 비밀번호를 만드세요.`;
})
.addCase(checkCurrentURL.rejected, (state) => {
// 유효하지 않은 url **
Copy link
Member Author

@live-small live-small May 15, 2022

Choose a reason for hiding this comment

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

비밀번호 재설정 페이지에 들어오자마자, query의 code로 유효한 코드인지 체크해서 만료된 코드일 경우 여기로 넘어오는데요, 여기서상태값을 이용해 잘못된 url이거나 삭제된 페이지라는 화면을 보여주려고 합니다.
-> 회의때 공유해서 토의함

@live-small live-small self-assigned this May 16, 2022
@live-small
Copy link
Member Author

live-small commented May 18, 2022

회의 내용(5월 18일)

  • 코드 만료시 보여질 페이지는 404페이지로 작업하기

    • 로그인 후에도 url 이상할경우, 404페이지로 이동
    • 어떻게 작업할지 고민해보기
  • 다수의 타입 리턴할 때 어떻게 처리할지

    • typeof로 매번 체크하기
      • 쓸때마다 typeof 조건문을 체크해서 번거로움
    • 받아올 타입 선언해, as로 단언하기 (채택)
      • queryString.parse로 받아올 때 as로 타입 단언하면, 이후에 편하게 쓸 수 있음
      • 다른 타입일 때 as로 단언하면 에러가 날 수 있는 단점이 있지만, 백엔드에서 넘겨주는 url(string)을 파싱하기때문에 다른 타입이 나올 가능성이 적다

@okinawaa
Copy link
Collaborator

좋습니당! 잘봤어요

@live-small
Copy link
Member Author

merge한 pr입니다, 코드리뷰용 입니다

Copy link
Collaborator

@kimyoungyin kimyoungyin left a comment

Choose a reason for hiding this comment

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

  • 남겨두셨던 다른 pr 비밀번호 재설정 기능 버그 수정  #93 이전 코드인 것 같아서 그 부분 제외하고 코멘트 남겨두었습니다!
  • 그리고 에러 페이지는 다른 곳에서도 쓰일 것 같아서 따로 만드는 게 좋아보입니다. state라는 건 rejected되었을 때 변경해줄 값이라고 보면 될까요?

@@ -90,6 +96,16 @@ const authSlice = createSlice({
state.isLogin = true;
setAccessTokenInAxiosHeaders(action.payload);
})
.addCase(resetPassword.fulfilled, (state, action) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

찾아보니 addMatcherisAllOf 등을 사용하는 방법이 있다네요? 정확히 맞는지는 모르겠지만 한 번 확인해보세요!
스크린샷 2022-09-07 오후 5 06 44


.error-message {
color: #ed4956;
font-size: 14px;
Copy link
Collaborator

Choose a reason for hiding this comment

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

프로젝트 기본 font-size가 14px 아니었나요?

Copy link
Member Author

Choose a reason for hiding this comment

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

// globalStyle.ts
  body, input,textarea ,button {
        font-size: 14px;
        line-height: 18px;
        padding:0;
        margin:0;
    }

globalStyle보니까 그렇네요..!!

Copy link
Collaborator

Choose a reason for hiding this comment

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

네네 저 부분은 중복되서 삭제해도 좋을 것 같아요!

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.

3 participants