|
1 | 1 | 'use client';
|
2 | 2 | import { useState } from 'react';
|
| 3 | +import { useRouter } from 'next/navigation'; |
3 | 4 | import { Button } from '@/components/ui/button';
|
4 | 5 | import { Checkbox } from '@/components/ui/checkbox';
|
5 | 6 | import { Input } from '@/components/ui/input';
|
6 | 7 | import Link from 'next/link';
|
7 | 8 | import { GithubIcon } from 'lucide-react';
|
| 9 | +import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; |
8 | 10 |
|
9 | 11 | export default function LoginForm() {
|
10 | 12 | const [email, setEmail] = useState('');
|
11 | 13 | const [password, setPassword] = useState('');
|
| 14 | + const [error, setError] = useState(''); |
| 15 | + // const [error, setError] = useState(''); |
| 16 | + const router = useRouter(); |
| 17 | + // handle login here |
| 18 | + const handleLogin = async (e: React.FormEvent) => { |
| 19 | + e.preventDefault(); |
| 20 | + // setError(''); |
| 21 | + // const apiEndpoint = 'http://localhost:4040/api/auth/login'; |
| 22 | + // const result = await fetch(apiEndpoint, { |
| 23 | + // method: 'POST', |
| 24 | + // headers: { |
| 25 | + // 'Content-Type': 'application/json', |
| 26 | + // }, |
| 27 | + // body: JSON.stringify({ email, password }), |
| 28 | + // }); |
| 29 | + |
| 30 | + // const data = await result.json(); |
| 31 | + // const message = data.message; |
| 32 | + // const isAuth = message === "Login successful"; |
| 33 | + const isAuth = false; |
| 34 | + if (isAuth) { |
| 35 | + // const token = data.token; |
| 36 | + // localStorage.setItem('token', token); |
| 37 | + // go to homepage |
| 38 | + router.push('/'); |
| 39 | + } else { |
| 40 | + setError('Please provide correct email and password'); |
| 41 | + console.error('Login failed'); |
| 42 | + } |
| 43 | + }; |
12 | 44 |
|
13 | 45 | return (
|
14 | 46 | <div className="flex min-h-screen items-center justify-center bg-gray-900">
|
15 | 47 | <div className="w-full max-w-md space-y-6 rounded-lg bg-gray-800 p-8 shadow-xl">
|
| 48 | + {error && ( |
| 49 | + <Alert variant="destructive" className="mb-4"> |
| 50 | + {/* <AlertCircle className="h-4 w-4" /> */} |
| 51 | + <AlertTitle>Error</AlertTitle> |
| 52 | + <AlertDescription>{error}</AlertDescription> |
| 53 | + </Alert> |
| 54 | + )} |
16 | 55 | <div className="text-center">
|
17 | 56 | <h2 className="text-3xl font-bold text-white">PeerPrep</h2>
|
18 | 57 | <p className="text-sm text-gray-400">Sign in to your account</p>
|
19 | 58 | </div>
|
20 |
| - <form className="space-y-4"> |
| 59 | + <form onSubmit={handleLogin} className="space-y-4"> |
21 | 60 | <div>
|
22 | 61 | <Input
|
23 | 62 | type="email"
|
@@ -86,7 +125,7 @@ export default function LoginForm() {
|
86 | 125 | </Button>
|
87 | 126 | </div>
|
88 | 127 | <div className="flex justify-center text-center text-sm text-gray-400">
|
89 |
| - Don't have an account? |
| 128 | + Do not have an account? |
90 | 129 | <span className="mx-1" />
|
91 | 130 | <Link href="/signup" className="text-blue-500 hover:underline">
|
92 | 131 | Sign up
|
|
0 commit comments