@@ -9,6 +9,7 @@ import { useRouter } from 'next/navigation';
9
9
import Link from 'next/link' ;
10
10
11
11
export default function SignUpPage ( ) {
12
+ const [ name , setName ] = useState ( '' ) ;
12
13
const [ email , setEmail ] = useState ( '' ) ;
13
14
const [ password , setPassword ] = useState ( '' ) ;
14
15
const [ confirmPassword , setConfirmPassword ] = useState ( '' ) ;
@@ -18,32 +19,27 @@ export default function SignUpPage() {
18
19
19
20
const handleSignUp = async ( e : React . FormEvent ) => {
20
21
e . preventDefault ( ) ;
21
- // setError('');
22
- // const apiEndpoint = 'http://localhost:4040/api/auth/signup';
23
- // const result = await fetch(apiEndpoint, {
24
- // method: 'POST',
25
- // headers: {
26
- // 'Content-Type': 'application/json',
27
- // },
28
- // body: JSON.stringify({ email, password }),
29
- // });
22
+ setError ( '' ) ;
23
+ const apiEndpoint = 'http://localhost:4040/signup' ;
24
+ const type = 'user' ;
25
+ const result = await fetch ( apiEndpoint , {
26
+ method : 'POST' ,
27
+ headers : {
28
+ 'Content-Type' : 'application/json' ,
29
+ } ,
30
+ body : JSON . stringify ( { email, name, password, type } ) ,
31
+ } ) ;
30
32
31
- // const data = await result.json();
32
- // const message = data.message;
33
- // const isAuth = message === "Login successful";
34
- const isAuth = true ;
33
+ const data = await result . json ( ) ;
35
34
if ( password !== confirmPassword ) {
36
35
setError ( 'Passwords do not match' ) ;
37
36
return ;
38
37
}
39
- if ( isAuth ) {
40
- // const token = data.token;
41
- // localStorage.setItem('token', token);
42
- // go to homepage
38
+ if ( false ) {
43
39
router . push ( '/' ) ;
44
40
} else {
45
- setError ( 'Account creation failed' ) ;
46
- console . error ( 'Login failed' ) ;
41
+ setError ( data . error || 'Account creation failed' ) ;
42
+ console . error ( 'Account creation failed' ) ;
47
43
}
48
44
} ;
49
45
@@ -68,6 +64,15 @@ export default function SignUpPage() {
68
64
</ p >
69
65
</ div >
70
66
< form onSubmit = { handleSignUp } className = "space-y-4" >
67
+ < div >
68
+ < Input
69
+ type = "text"
70
+ placeholder = "Name"
71
+ value = { name }
72
+ onChange = { ( e ) => setName ( e . target . value ) }
73
+ className = "w-full rounded-md border border-gray-600 bg-gray-700 px-3 py-2 text-sm text-white placeholder-gray-400 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500"
74
+ />
75
+ </ div >
71
76
< div >
72
77
< Input
73
78
type = "email"
0 commit comments