Skip to content

Commit

Permalink
[FEAT] - 로그인 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
liupei8979 committed Sep 28, 2024
1 parent e48f918 commit 968e7b7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/pages/login.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import { API } from '../lib/api';
import cn from '../lib/cn.ts';
import { useNavigate } from 'react-router-dom';
import { useState } from 'react';

export default function Login() {
const navigate = useNavigate();

// 입력 필드 상태 관리
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');

const handleLogin = async () => {
try {
// 로그인 요청
await API.User.login(username, password);
alert('로그인 성공!');
navigate('/'); // 로그인 성공 시 메인 페이지로 이동
} catch (error) {
console.error('로그인 실패:', error);
alert('로그인에 실패했습니다.');
}
};

return (
<div
className={cn(
Expand All @@ -29,6 +47,8 @@ export default function Login() {
)}
type="text"
placeholder="아이디"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
<input
className={cn(
Expand All @@ -37,6 +57,8 @@ export default function Login() {
)}
type="password"
placeholder="비밀번호"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
</div>

Expand All @@ -47,6 +69,7 @@ export default function Login() {
'w-[500px] h-[70px] bg-[#5A82F1] text-white font-bold rounded',
'hover:bg-[#4A72D1] focus:outline-none focus:ring-2 focus:ring-[#5A82F1]'
)}
onClick={handleLogin} // 로그인 버튼 클릭 시 실행
>
로그인
</button>
Expand Down

0 comments on commit 968e7b7

Please sign in to comment.