|
1 | | -import { FormField } from '@/components/auth/FormField'; |
| 1 | +'use client'; |
| 2 | + |
| 3 | +import FormField from '@/components/auth/FormField'; |
2 | 4 | import { FaGithub } from 'react-icons/fa'; |
3 | | -import { Button } from '@/components/auth/Button'; |
| 5 | +import Button from '@/components/auth/Button'; |
4 | 6 | 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'; |
5 | 14 |
|
6 | 15 | type LoginFormProps = { |
7 | 16 | handleOpenModal: () => void; |
8 | 17 | }; |
9 | 18 |
|
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 | + |
11 | 39 | return ( |
12 | 40 | <> |
13 | 41 | <div className="space-y-6"> |
@@ -41,8 +69,10 @@ export function LoginForm({ handleOpenModal }: LoginFormProps) { |
41 | 69 |
|
42 | 70 | <Button variant="github"> |
43 | 71 | <FaGithub className="text-xl" /> |
44 | | - <span>Github로 로그인</span> |
| 72 | + <span onClick={handleGithubLogin}>Github로 로그인</span> |
45 | 73 | </Button> |
46 | 74 | </> |
47 | 75 | ); |
48 | | -} |
| 76 | +}; |
| 77 | + |
| 78 | +export default LoginForm; |
0 commit comments