diff --git a/FE/src/components/Login/Input.tsx b/FE/src/components/Login/Input.tsx index cb910d07..b6b78ab1 100644 --- a/FE/src/components/Login/Input.tsx +++ b/FE/src/components/Login/Input.tsx @@ -1,16 +1,12 @@ -import { HTMLInputTypeAttribute } from 'react'; +import { ComponentProps } from 'react'; -type LoginInputProps = { - type: HTMLInputTypeAttribute; - placeholder: string; -}; +type LoginInputProps = ComponentProps<'input'>; -export default function Input({ type, placeholder }: LoginInputProps) { +export default function Input({ ...props }: LoginInputProps) { return ( ); } diff --git a/FE/src/components/Login/index.tsx b/FE/src/components/Login/index.tsx index ce03ff78..c8be634f 100644 --- a/FE/src/components/Login/index.tsx +++ b/FE/src/components/Login/index.tsx @@ -1,30 +1,57 @@ import useLoginModalStore from 'store/useLoginModalStore'; import Input from './Input'; import { ChatBubbleOvalLeftIcon } from '@heroicons/react/16/solid'; +import { FormEvent, useState } from 'react'; +import { login } from 'service/auth'; export default function Login() { const { isOpen, toggleModal } = useLoginModalStore(); + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); if (!isOpen) return; + const handleSubmit = async (e: FormEvent) => { + e.preventDefault(); + const res = await login(email, password); + + if ('error' in res) { + return; + } + + console.log(res); + }; + return ( <> toggleModal()} /> JuGa - - - - - + + + setEmail(e.target.value)} + autoComplete='username' + /> + setPassword(e.target.value)} + autoComplete='current-password' + /> + 로그인 - - - 카카오 계정으로 로그인 - - + + + + 카카오 계정으로 로그인 + > ); diff --git a/FE/src/service/auth.ts b/FE/src/service/auth.ts new file mode 100644 index 00000000..e4ecb640 --- /dev/null +++ b/FE/src/service/auth.ts @@ -0,0 +1,15 @@ +import { LoginFailResponse, LoginSuccessResponse } from 'types'; + +export async function login( + email: string, + password: string, +): Promise { + return fetch('http://223.130.151.42:3000/auth/login', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + email, + password, + }), + }).then((res) => res.json()); +} diff --git a/FE/src/types.ts b/FE/src/types.ts new file mode 100644 index 00000000..06b1b10b --- /dev/null +++ b/FE/src/types.ts @@ -0,0 +1,9 @@ +export type LoginSuccessResponse = { + accessToken: string; +}; + +export type LoginFailResponse = { + error: string; + message: string[]; + statusCode: number; +};
카카오 계정으로 로그인