-
Notifications
You must be signed in to change notification settings - Fork 53
[이찬주] Week5 #214
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
Open
ckswnskfk
wants to merge
12
commits into
codeit-bootcamp-frontend:part1-이찬주
Choose a base branch
from
ckswnskfk:part1-이찬주-week5
base: part1-이찬주
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "part1-\uC774\uCC2C\uC8FC-week5"
Open
[이찬주] Week5 #214
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d657b26
Refactor: 에러 메세지 핸들러 수정
ckswnskfk 9f33a81
Fix: handleErrorMessage 함수 수정
ckswnskfk dd6d58e
Rename: api와 이름 맞추기 위해 member에서 auth로 폴더명 변경
ckswnskfk 42d1dfa
Feat: 공통 fetch 기능의 fetchApi 생성, 도메인 별 api 폴더 구조 생성
ckswnskfk 429e758
Remove: api 파일 삭제 -> 각 페이지 폴더에 작성
ckswnskfk adee9ae
Feat: 로그인 기능, email check 기능 완성
ckswnskfk d182a04
Remove: 더미 데이터 제공하는 users.js 삭제
ckswnskfk 2e8f2b1
Feat: 회원가입 기능 완성
ckswnskfk 45baa48
Feat: 랜딩 페이지 심화 요구사항 완성
ckswnskfk b6fb128
Feat: url 직접 접근 시에도 토큰에 따른 페이지 이동 기능 추가
ckswnskfk 804c08a
Rename: 이벤트 함수명 좀 더 명확하게 변경
ckswnskfk 0441b3b
Refactor: 코드 리뷰 사항 반영
ckswnskfk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| const signInAnchor = document.querySelector(".gnb__signin"); | ||
| const signUpAnchor = document.querySelector(".hero__signup"); | ||
|
|
||
| signInAnchor.addEventListener("click", (e) => { | ||
| e.preventDefault(); | ||
| navigateFolderPage("/pages/auth/signin/"); | ||
| }); | ||
|
|
||
| signUpAnchor.addEventListener("click", (e) => { | ||
| e.preventDefault(); | ||
| navigateFolderPage("/pages/auth/signup/"); | ||
| }); | ||
|
|
||
| function navigateFolderPage(href) { | ||
| if (localStorage.getItem("accessToken")) { | ||
| location.href = "/pages/folder/"; | ||
| return; | ||
| } | ||
|
|
||
| location.href = href; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { fetchApi } from "/scripts/fetchApi.js"; | ||
|
|
||
| const postSignIn = (email, password) => | ||
| fetchApi.post("/sign-in", { body: { email, password } }); | ||
|
|
||
| const postCheckEmail = (email) => | ||
| fetchApi.post("/check-email", { body: { email } }); | ||
|
|
||
| const postSignUp = (email, password) => | ||
| fetchApi.post("/sign-up", { body: { email, password } }); | ||
|
|
||
| export { postCheckEmail, postSignIn, postSignUp }; |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { | ||
| changePasswordVisibility, | ||
| checkEmailValid, | ||
| checkPasswordValid, | ||
| errorMessage, | ||
| inputValidationFailed, | ||
| inputValidationSucceeded, | ||
| setUserAccessToken, | ||
| } from "../sign.js"; | ||
|
|
||
| import { postSignIn } from "../api.js"; | ||
| import { isEmptyString } from "/scripts/utils.js"; | ||
|
|
||
| navigateFolderPage("pages/auth/signin/"); | ||
|
|
||
| /** | ||
| * email input | ||
| */ | ||
| const emailInput = document.querySelector("#input-email"); | ||
| emailInput.addEventListener("focusout", onEmailFocusout); | ||
|
|
||
| async function onEmailFocusout({ target }) { | ||
| const errorMessage = await checkEmailValid(target, false); | ||
| if (!isEmptyString(errorMessage)) { | ||
| inputValidationFailed(target, errorMessage); | ||
| return false; | ||
| } | ||
|
|
||
| inputValidationSucceeded(target); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * password input | ||
| */ | ||
| const passwordInput = document.querySelector("#input-password"); | ||
| const passwordEyeIcon = document.querySelector( | ||
| ".form__password .form__input--eye-off" | ||
| ); | ||
|
|
||
| passwordInput.addEventListener("focusout", onPasswordFocusout); | ||
|
|
||
| function onPasswordFocusout({ target }) { | ||
| const errorMessage = checkPasswordValid(target); | ||
| if (!isEmptyString(errorMessage)) { | ||
| inputValidationFailed(target, errorMessage, passwordEyeIcon); | ||
| return false; | ||
| } | ||
|
|
||
| inputValidationSucceeded(target, passwordEyeIcon); | ||
| return true; | ||
| } | ||
|
|
||
| passwordEyeIcon.addEventListener( | ||
| "click", | ||
| changePasswordVisibility(passwordInput) | ||
| ); | ||
|
|
||
| /** | ||
| * form | ||
| */ | ||
| const form = document.querySelector(".form"); | ||
|
|
||
| form.addEventListener("submit", onSubmit); | ||
|
|
||
| function onSubmit(e) { | ||
| e.preventDefault(); | ||
|
|
||
| const validResult = | ||
| onEmailFocusout({ target: emailInput }) && | ||
| onPasswordFocusout({ target: passwordInput }); | ||
|
|
||
| if (!validResult) { | ||
| return; | ||
| } | ||
|
|
||
| doSignIn(emailInput.value, passwordInput.value); | ||
| } | ||
|
|
||
| async function doSignIn(email, password) { | ||
| try { | ||
| const signInResponse = await postSignIn(email, password); | ||
| setUserAccessToken(signInResponse); | ||
| location.href = "/pages/folder"; | ||
| } catch (error) { | ||
| console.error(`${error.name}: ${error.message}`); | ||
| if (error.name === "AuthApiError") { | ||
| inputValidationFailed(emailInput, errorMessage.email.loginFailed); | ||
| inputValidationFailed( | ||
| passwordInput, | ||
| errorMessage.password.loginFailed, | ||
| passwordEyeIcon | ||
| ); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 이런 방법도 생각해 볼 수 있겠군요! 좋습니다 ㅎㅎ
나중 얘기지만 도움이 될 수 있을 부분일거 같아 미리 말씀드리면
통신 과정에서 사용자의 인증을 위해 헤더에 토큰을 넣어서 함께 보내는 경우가 많이 있습니다.
이 과정에서 axios를 이용한 인터셉터를 적용할 수 있는데,
인터셉터는 통신 전 해당 요청을 가로채서 어떠한 작업을 거친 후 다시 통신을 보내는 방식을 뜻합니다.
지금 구현한 기능과는 조금 방식이 다르지만, 어쨋든 지금도 페이지 이동 전 토큰 유무를 확인한 뒤
그에 따라 페이지를 이동하는 것이라서 어떻게 보면 작은 인터셉터라고도 할 수 있겠네요 ㅎㅎㅎ
갑자기 생각나서 해당 내용에 대해 전달드려봅니다..ㅎㅎ
인터셉터와 관련된 글도 링크로 전달드릴테니, 차후에 한번 적용해보세요!
https://www.timegambit.com/blog/digging/axios/01
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 좀 더 확실한 방법이겠네요!
제가 한 방식은 직접 url을 입력해서 접근하는 방식에는 통하지 않아서..ㅋㅋㅋ
지식 전수 감사합니다!:smile: