This repository was archived by the owner on Nov 8, 2023. It is now read-only.
forked from codesquad-members-2023/FineAnts-team-02
-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] OAuth SignIn 구현 #42
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
20618fa
#4 feat: Sign up data에 passwordConfirm field 추가
Kakamotobi 39aee66
#4 feat: Sign up, 닉네임/이메일 중복검사 api 및 mock 추가
Kakamotobi eecf64c
#4 fix: useText 초기값 validate 적용
Kakamotobi d255467
#4 feat: NicknameSubPage "다음" 버튼 disabled 조건 적용
Kakamotobi bfbe37f
#4 feat: Email verification code api 및 mock 추가
Kakamotobi 15228c8
#4 feat: Sign up subpage "다음" 버튼 disabled 조건 추가
Kakamotobi 9ff9762
#4 feat: Signup nickname 중복 체크 기능 추가
Kakamotobi 6e8cef7
#4 feat: Signup email 중복 체크 기능 추가
Kakamotobi 2d85e91
#4 feat: Signup password confirm mismatch 에러 메시지 추가
Kakamotobi d009390
#4 feat: Signup email verification code 요청 추가
Kakamotobi 0ec3377
#4 feat: Google SignIn 추가
Kakamotobi 77bdfb7
#4 feat: Popup window 구현
Kakamotobi 2472c39
#4 feat: Kakao 로그인 버튼 구현
Kakamotobi d08a930
#4 feat: Naver 로그인 버튼 구현
Kakamotobi 09f2f46
#4 style: console.log 제거
Kakamotobi 47ee0f3
#4 fix: Window.naver doesn't exist type error
Kakamotobi dc4f126
#4 refactor: KakaoSignInButton oAuthPopUpWindow type guard 적용
Kakamotobi a654e24
#4 refactor: Env variables 상수화
Kakamotobi 07a3f10
Merge branch 'dev-fe' into fe/feat/#4-signup-page
Kakamotobi 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 contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,26 @@ | ||
import useOAuthSignInMutation from "@api/auth/queries/useOAuthSignInMutation"; | ||
import { GoogleLogin } from "@react-oauth/google"; | ||
|
||
export default function GoogleSignInButton() { | ||
const { mutate: oAuthSignInMutate } = useOAuthSignInMutation(); | ||
|
||
return ( | ||
// TODO: custom login button (`useGoogleLogin` "auth-code" flow) | ||
<GoogleLogin | ||
onSuccess={(credentialResponse) => { | ||
const authCode = credentialResponse.credential; | ||
|
||
if (authCode) { | ||
oAuthSignInMutate({ | ||
provider: "google", | ||
authCode, | ||
}); | ||
} | ||
}} | ||
onError={() => { | ||
// TODO: Handle error from Google | ||
console.log("Login Failed"); | ||
}} | ||
/> | ||
); | ||
} |
This file contains 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,39 @@ | ||
import kakaoLoginButtonImage from "@assets/images/kakao_login_medium_wide.png"; | ||
import { CLIENT_URL, KAKAO_CLIENT_ID } from "@constants/config"; | ||
import { WindowContext } from "@context/WindowContext"; | ||
import openPopUpWindow from "@utils/openPopUpWindow"; | ||
import { useContext } from "react"; | ||
import { styled } from "styled-components"; | ||
|
||
export default function KakaoSignInButton() { | ||
const { onOpenPopUpWindow } = useContext(WindowContext); | ||
|
||
const onKakaoSignIn = () => { | ||
const oAuthPopUpWindow = openPopUpWindow( | ||
`https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=${KAKAO_CLIENT_ID}&redirect_uri=${CLIENT_URL}/signin?provider=kakao`, | ||
"kakaoOAuth", | ||
500, | ||
600 | ||
); // TODO: handle case where popup doesn't show (Ex: user blocked popups) | ||
|
||
if (oAuthPopUpWindow) { | ||
onOpenPopUpWindow(oAuthPopUpWindow); | ||
} | ||
}; | ||
|
||
return ( | ||
<StyledKakaoSignInButton type="button" onClick={onKakaoSignIn}> | ||
<img src={kakaoLoginButtonImage} alt="카카오 로그인" /> | ||
</StyledKakaoSignInButton> | ||
); | ||
} | ||
|
||
const StyledKakaoSignInButton = styled.button` | ||
width: 228px; | ||
height: 44px; | ||
|
||
img { | ||
width: 100%; | ||
object-fit: fill; | ||
} | ||
`; |
This file contains 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,24 @@ | ||
import { CLIENT_URL, NAVER_CLIENT_ID } from "@constants/config"; | ||
import { useEffect } from "react"; | ||
import styled from "styled-components"; | ||
|
||
export default function NaverSignInButton() { | ||
const naverLogin = new (window as any).naver.LoginWithNaverId({ | ||
clientId: NAVER_CLIENT_ID, | ||
callbackUrl: `${CLIENT_URL}/signin?provider=naver`, | ||
isPopup: true, | ||
loginButton: { | ||
color: "green", | ||
type: 3, | ||
height: 40, | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
naverLogin.init(); | ||
}, []); | ||
|
||
return <StyledNaverSignInButton id="naverIdLogin" />; | ||
} | ||
|
||
const StyledNaverSignInButton = styled.div``; |
This file contains 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,15 @@ | ||
export const CLIENT_URL = | ||
process.env.NODE_ENV === "production" | ||
? import.meta.env.VITE_CLIENT_URL_PROD | ||
: import.meta.env.VITE_CLIENT_URL_DEV; | ||
|
||
export const BASE_API_URL = | ||
process.env.NODE_ENV === "production" | ||
? import.meta.env.VITE_API_URL_PROD | ||
: import.meta.env.VITE_API_URL_DEV; | ||
|
||
export const GOOGLE_CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID; | ||
|
||
export const KAKAO_CLIENT_ID = import.meta.env.VITE_KAKAO_CLIENT_ID; | ||
|
||
export const NAVER_CLIENT_ID = import.meta.env.VITE_NAVER_CLIENT_ID; |
This file contains 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,33 @@ | ||
import { ReactNode, createContext, useState } from "react"; | ||
|
||
export const WindowContext = createContext<{ | ||
popUpWindow: Window | null; | ||
onOpenPopUpWindow: (targetWindow: Window) => void; | ||
closePopUpWindow: () => void; | ||
}>({ | ||
popUpWindow: null, | ||
onOpenPopUpWindow: () => {}, | ||
closePopUpWindow: () => {}, | ||
}); | ||
|
||
export function WindowProvider({ children }: { children: ReactNode }) { | ||
const [popUpWindow, setPopUpWindow] = useState<Window | null>(null); | ||
|
||
const onOpenPopUpWindow = (targetWindow: Window) => { | ||
setPopUpWindow(targetWindow); | ||
}; | ||
|
||
const closePopUpWindow = () => { | ||
if (popUpWindow) { | ||
popUpWindow.close(); | ||
setPopUpWindow(null); | ||
} | ||
}; | ||
|
||
return ( | ||
<WindowContext.Provider | ||
value={{ popUpWindow, onOpenPopUpWindow, closePopUpWindow }}> | ||
{children} | ||
</WindowContext.Provider> | ||
); | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { setupWorker } from "msw"; | ||
import handlers from "./handlers/index"; | ||
import handlers from "./handlers"; | ||
|
||
export default setupWorker(...handlers); |
This file contains 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,62 @@ | ||
import { HTTPSTATUS } from "@api/types"; | ||
|
||
export const successfulSignUpData = { | ||
code: HTTPSTATUS.created, | ||
status: "Created", | ||
message: "회원가입이 완료되었습니다", | ||
data: { | ||
member: { | ||
nickname: "Kakamotobi", | ||
email: "[email protected]", | ||
}, | ||
}, | ||
}; | ||
|
||
export const unsuccessfulSignUpData = { | ||
code: HTTPSTATUS.badRequest, | ||
status: "Bad Request", | ||
message: "회원가입이 실패했습니다", | ||
data: null, | ||
}; | ||
|
||
export const successfulNicknameDuplicationCheckData = { | ||
code: HTTPSTATUS.success, | ||
status: "Success", | ||
message: "닉네임이 사용 가능합니다", | ||
data: null, | ||
}; | ||
|
||
export const unsuccessfulNicknameDuplicationCheckData = { | ||
code: HTTPSTATUS.badRequest, | ||
status: "Bad Request", | ||
message: "닉네임이 중복되었습니다", | ||
data: null, | ||
}; | ||
|
||
export const successfulEmailDuplicationCheckData = { | ||
code: HTTPSTATUS.success, | ||
status: "Success", | ||
message: "이메일이 사용 가능합니다", | ||
data: null, | ||
}; | ||
|
||
export const unsuccessfulEmailDuplicationCheckData = { | ||
code: HTTPSTATUS.badRequest, | ||
status: "Bad Request", | ||
message: "이메일이 중복되었습니다", | ||
data: null, | ||
}; | ||
|
||
export const successfulEmailVerificationData = { | ||
code: HTTPSTATUS.success, | ||
status: "Success", | ||
message: "이메일로 검증코드를 전송하였습니다", | ||
data: null, | ||
}; | ||
|
||
export const unsuccessfulEmailVerificationData = { | ||
code: HTTPSTATUS.badRequest, | ||
status: "Bad Request", | ||
message: "이메일 검증코드 전송을 실패했습니다", | ||
data: null, | ||
}; |
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.
이렇게 초기값을 안주고 undefined로 사용할 수도 있는데 null을 사용하신 이유가 undefined와 null의 영어적 의미나 뜻 때문인가요?
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.
undefined
의 정의("변수가 선언은 되었지만 아직 값을 할당받지 않았다")를 보았을 때는undefined
가 적절한 것 같지만, popup window를 닫을 때setPopUpWindow(undefined)
는 어색한 것 같아요. 저는 개인적으로undefined
는 처음에 변수를 선언할 때는 빈 값으로서 괜찮지만 후에 값이 생겼다가 없애는 경우에는null
("값이 없다")이 더 적절한 것 같아서null
을 사용했습니다.https://stackoverflow.com/a/57249968/15330887
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.
저도
setPopUpWindow(undefined)
처럼 undefined로 set하는다는게 조금 어색하게 느껴져서 물어본 질문 이였습니다👍