Skip to content

Commit 68df4b0

Browse files
committed
feat: 깃허브 소셜 로그인
1 parent 8f2494e commit 68df4b0

4 files changed

Lines changed: 51 additions & 16 deletions

File tree

app/(auth)/login/page.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use client';
22

3-
import { AuthCard } from '@/components/auth/AuthCard';
4-
import { FindPasswordModal } from '@/components/auth/FindPasswordModal';
5-
import { LoginForm } from '@/components/auth/LoginForm';
3+
import AuthCard from '@/components/auth/AuthCard';
4+
import FindPasswordModal from '@/components/auth/FindPasswordModal';
5+
import LoginForm from '@/components/auth/LoginForm';
66
import { useState } from 'react';
77

8-
export default function Page() {
8+
const Page = () => {
99
// 비밀번호 재설정 모달 state
1010
const [isModalOpen, setIsModalOpen] = useState(false);
1111

@@ -25,4 +25,6 @@ export default function Page() {
2525
{isModalOpen && <FindPasswordModal onClose={handleCloseModal} />}
2626
</div>
2727
);
28-
}
28+
};
29+
30+
export default Page;

app/(auth)/signup/page.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { AuthCard } from '@/components/auth/AuthCard';
2-
import { SignupForm } from '@/components/auth/SignupForm';
3-
export default function Page() {
1+
import AuthCard from '@/components/auth/AuthCard';
2+
import SignupForm from '@/components/auth/SignupForm';
3+
4+
const Page = () => {
45
return (
56
<div className="bg-background">
67
<AuthCard title="회원가입" description="회원가입하여 계정을 생성하세요">
78
<SignupForm />
89
</AuthCard>
910
</div>
1011
);
11-
}
12+
};
13+
14+
export default Page;

components/auth/LoginForm.tsx

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
1-
import { FormField } from '@/components/auth/FormField';
1+
'use client';
2+
3+
import FormField from '@/components/auth/FormField';
24
import { FaGithub } from 'react-icons/fa';
3-
import { Button } from '@/components/auth/Button';
5+
import Button from '@/components/auth/Button';
46
import Link from 'next/link';
7+
import { auth } from '@/lib/firebase';
8+
import {
9+
GithubAuthProvider,
10+
signInWithPopup,
11+
UserCredential,
12+
} from 'firebase/auth';
13+
import { useRouter } from 'next/navigation';
514

615
type LoginFormProps = {
716
handleOpenModal: () => void;
817
};
918

10-
export function LoginForm({ handleOpenModal }: LoginFormProps) {
19+
const LoginForm = ({ handleOpenModal }: LoginFormProps) => {
20+
const router = useRouter();
21+
22+
const githubProvider = new GithubAuthProvider();
23+
const handleGithubLogin = async () => {
24+
try {
25+
const result: UserCredential = await signInWithPopup(
26+
auth,
27+
githubProvider
28+
);
29+
const user = result.user;
30+
console.log('로그인 성공 : ', user);
31+
router.push('/main');
32+
} catch (error: unknown) {
33+
if (error instanceof Error) {
34+
console.log('로그인 에러 : ', error.message);
35+
}
36+
}
37+
};
38+
1139
return (
1240
<>
1341
<div className="space-y-6">
@@ -41,8 +69,10 @@ export function LoginForm({ handleOpenModal }: LoginFormProps) {
4169

4270
<Button variant="github">
4371
<FaGithub className="text-xl" />
44-
<span>Github로 로그인</span>
72+
<span onClick={handleGithubLogin}>Github로 로그인</span>
4573
</Button>
4674
</>
4775
);
48-
}
76+
};
77+
78+
export default LoginForm;

lib/firebase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Import the functions you need from the SDKs you need
22
import { initializeApp } from 'firebase/app';
3-
import { getAnalytics } from 'firebase/analytics';
3+
// import { getAnalytics } from 'firebase/analytics';
44
import { getAuth } from 'firebase/auth';
55
import { getFirestore } from 'firebase/firestore';
66
// TODO: Add SDKs for Firebase products that you want to use
@@ -20,7 +20,7 @@ const firebaseConfig = {
2020

2121
// Initialize Firebase
2222
const app = initializeApp(firebaseConfig);
23-
const analytics = getAnalytics(app);
23+
// const analytics = getAnalytics(app);
2424

2525
export const auth = getAuth(app);
2626
export const db = getFirestore(app);

0 commit comments

Comments
 (0)