-
Notifications
You must be signed in to change notification settings - Fork 3
feat: 소셜 로그인 통합 및 상태 관리, 라우터 레이아웃 분리 #23
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
Merged
tkyoun0421
merged 10 commits into
amicable-development-center:develop
from
namee-h:feat/login
Jun 24, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
68d80ce
refactor: github 로그인 에러 핸들링 early return 방식으로 리팩토링
namee-h d10d933
refactor: 소셜 로그인 훅 통합에 따른 LoginForm 훅 호출 구조 수정
namee-h fb8260d
style: socialButton 컴포넌트 export 아래로 선언 위치 변경
namee-h 71f9a96
Merge branch 'develop' into feat/login
namee-h 102a028
feat: zustand 기반 전역 인증 상태 관리 로직 추가
namee-h 771367e
feat: header 컴포넌트 생성 및 로그인/로그아웃 버튼 상태 분기 적용
namee-h 54e44ce
style: styled component 위치 수정
namee-h 1aa693d
feat: 라우터 레이아웃 분리 및 로그인/회원가입 페이지 헤더 제거
namee-h 7dd9152
style: header 컴포넌트 배경색 및 패딩 스타일 수정
namee-h e2b4356
fix: useAuthObserver 훅 반환 타입 명시하여 린트 에러 수정
namee-h 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 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,12 @@ | ||
| import type { JSX } from "react"; | ||
| import { Outlet } from "react-router-dom"; | ||
|
|
||
| const AuthLayout = (): JSX.Element => { | ||
| return ( | ||
| <main> | ||
| <Outlet /> | ||
| </main> | ||
| ); | ||
| }; | ||
|
|
||
| export default AuthLayout; |
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,17 @@ | ||
| import type { JSX } from "react"; | ||
| import { Outlet } from "react-router-dom"; | ||
|
|
||
| import Header from "@widgets/Header/Header"; | ||
|
|
||
| const MainLayout = (): JSX.Element => { | ||
| return ( | ||
| <> | ||
| <Header /> | ||
| <main> | ||
| <Outlet /> | ||
| </main> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default MainLayout; |
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { signInWithPopup, fetchSignInMethodsForEmail } from "firebase/auth"; | ||
| import type { AuthProvider } from "firebase/auth"; | ||
| import { useNavigate } from "react-router-dom"; | ||
|
|
||
| import { auth } from "@shared/firebase/firebase"; | ||
|
|
||
| export const useSocialLogin = (): { | ||
| socialLogin: (provider: AuthProvider) => Promise<void>; | ||
| } => { | ||
| const navigate = useNavigate(); | ||
|
|
||
| const socialLogin = async (provider: AuthProvider): Promise<void> => { | ||
| try { | ||
| const result = await signInWithPopup(auth, provider); | ||
| const user = result.user; | ||
|
|
||
| console.log("소셜 로그인 성공: ", user); | ||
| navigate("/"); | ||
| } catch (error: any) { | ||
| console.error("소셜 로그인 실패: ", error); | ||
|
|
||
| if (error.code !== "auth/account-exists-with-different-credential") | ||
| return; | ||
|
|
||
| const email = error.customData?.email; | ||
| if (!email) { | ||
| alert("이메일 정보를 가져올 수 없습니다."); | ||
| return; | ||
| } | ||
|
|
||
| const methods = await fetchSignInMethodsForEmail(auth, email); | ||
| if (methods.length === 0) { | ||
| alert("이미 다른 로그인 방법으로 가입된 이메일입니다."); | ||
| return; | ||
| } | ||
|
|
||
| if (methods.includes("google.com")) { | ||
| alert( | ||
| "이미 Google 계정으로 가입된 이메일입니다. Google 로그인을 이용해주세요." | ||
| ); | ||
| } else { | ||
| alert(`이미 가입된 로그인 방법: ${methods.join(", ")}`); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| return { socialLogin }; | ||
| }; | ||
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,15 @@ | ||
| import { Button } from "@mui/material"; | ||
| import type { JSX } from "react"; | ||
| import { useNavigate } from "react-router-dom"; | ||
|
|
||
| const LoginButton = (): JSX.Element => { | ||
| const navigate = useNavigate(); | ||
|
|
||
| return ( | ||
| <Button variant="outlined" onClick={() => navigate("/login")}> | ||
| 로그인 | ||
| </Button> | ||
| ); | ||
| }; | ||
|
|
||
| export default LoginButton; |
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,23 @@ | ||
| import { Button } from "@mui/material"; | ||
| import { signOut } from "firebase/auth"; | ||
| import type { JSX } from "react"; | ||
|
|
||
| import { auth } from "@shared/firebase/firebase"; | ||
| import { useAuthStore } from "@shared/stores/authStore"; | ||
|
|
||
| const LogoutButton = (): JSX.Element => { | ||
| const logout = useAuthStore((state) => state.logout); | ||
|
|
||
| const handleLogout = async (): Promise<void> => { | ||
| await signOut(auth); | ||
| logout(); | ||
| }; | ||
|
|
||
| return ( | ||
| <Button variant="outlined" onClick={handleLogout}> | ||
| 로그아웃 | ||
| </Button> | ||
| ); | ||
| }; | ||
|
|
||
| export default LogoutButton; |
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,19 @@ | ||
| import { onAuthStateChanged } from "firebase/auth"; | ||
| import { useEffect } from "react"; | ||
|
|
||
| import { auth } from "@shared/firebase/firebase"; | ||
| import { useAuthStore } from "@shared/stores/authStore"; | ||
|
|
||
| export const useAuthObserver = (): void => { | ||
| const setUser = useAuthStore((state) => state.setUser); | ||
| const setLoading = useAuthStore((state) => state.setLoading); | ||
|
|
||
| useEffect(() => { | ||
| const unsubscribe = onAuthStateChanged(auth, (user) => { | ||
| setUser(user); | ||
| setLoading(false); | ||
| }); | ||
|
|
||
| return () => unsubscribe(); | ||
| }, [setUser, setLoading]); | ||
| }; |
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,20 @@ | ||
| import type { User } from "firebase/auth"; | ||
| import { create } from "zustand"; | ||
|
|
||
| interface AuthState { | ||
| user: User | null; | ||
| isLoading: boolean; | ||
| setUser: (user: User | null) => void; | ||
| setLoading: (loading: boolean) => void; | ||
| logout: () => void; | ||
| } | ||
|
|
||
| export const useAuthStore = create<AuthState>((set) => ({ | ||
| user: null, | ||
| isLoading: true, | ||
|
|
||
| setUser: (user) => set({ user }), | ||
| setLoading: (loading) => set({ isLoading: loading }), | ||
|
|
||
| logout: () => set({ user: 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.
바꿔주셨네요!! 👍 👍
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.
옙! 수정했습니다 ㅋㅋㅋㅋ