3
3
4
4
import { useState } from "react" ;
5
5
import { createUserWithEmailAndPassword } from "firebase/auth" ;
6
- import { auth } from "@ /firebase/config " ;
6
+ import { auth } from ".. /firebase" ;
7
7
import { useRouter } from "next/navigation" ;
8
8
import Link from "next/link" ;
9
- import { FaEnvelope , FaLock , FaUserPlus } from "react-icons/fa" ;
9
+ import { FaEnvelope , FaLock } from "react-icons/fa" ;
10
10
11
11
export default function RegisterPage ( ) {
12
12
const [ email , setEmail ] = useState ( "" ) ;
@@ -15,6 +15,7 @@ export default function RegisterPage() {
15
15
const [ error , setError ] = useState ( "" ) ;
16
16
const [ loading , setLoading ] = useState ( false ) ;
17
17
const router = useRouter ( ) ;
18
+ const basePath = "/crypt-webapp" ;
18
19
19
20
const handleSubmit = async ( e ) => {
20
21
e . preventDefault ( ) ;
@@ -26,118 +27,93 @@ export default function RegisterPage() {
26
27
}
27
28
28
29
setLoading ( true ) ;
30
+
29
31
try {
30
32
await createUserWithEmailAndPassword ( auth , email , password ) ;
31
- router . push ( "/dashboard" ) ;
32
- } catch ( error ) {
33
- console . error ( "Registration error:" , error ) ;
34
- setError ( error . message ) ;
35
- } finally {
36
- setLoading ( false ) ;
33
+ router . push ( `${ basePath } /dashboard` ) ;
34
+ } catch ( err ) {
35
+ setError ( "Failed to create an account. Please try again." ) ;
36
+ console . error ( err ) ;
37
37
}
38
+
39
+ setLoading ( false ) ;
38
40
} ;
39
41
40
42
return (
41
- < div className = "flex items-center justify-center min-h-screen py-12 px-4 sm:px-6 lg:px-8" >
42
- < div className = "max-w-md w-full space-y-8 bg-[#111827] p-8 rounded-2xl shadow-xl " >
43
+ < div className = "min-h-screen flex items-center justify-center bg-gray-900 py-12 px-4 sm:px-6 lg:px-8" >
44
+ < div className = "max-w-md w-full space-y-8" >
43
45
< div >
44
46
< h2 className = "mt-6 text-center text-3xl font-extrabold text-white" >
45
- Create your account
47
+ Create an account
46
48
</ h2 >
47
49
</ div >
48
50
49
51
{ error && (
50
- < div className = "bg-red-500/10 text-red-500 p-3 rounded-lg text-sm" >
51
- { error }
52
- </ div >
52
+ < div className = "text-red-500 text-sm text-center" > { error } </ div >
53
53
) }
54
54
55
55
< form className = "mt-8 space-y-6" onSubmit = { handleSubmit } >
56
- < div className = "rounded-md shadow-sm space-y-4" >
57
- < div >
58
- < label htmlFor = "email" className = "sr-only" >
59
- Email address
60
- </ label >
61
- < div className = "relative" >
62
- < div className = "absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none" >
63
- < FaEnvelope className = "h-5 w-5 text-gray-400" />
64
- </ div >
65
- < input
66
- id = "email"
67
- name = "email"
68
- type = "email"
69
- autoComplete = "email"
70
- required
71
- value = { email }
72
- onChange = { ( e ) => setEmail ( e . target . value ) }
73
- className = "appearance-none relative block w-full px-3 py-2 pl-10 bg-gray-900 border border-gray-600 placeholder-gray-400 text-white rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
74
- placeholder = "Email address"
75
- />
76
- </ div >
56
+ < div className = "rounded-md shadow-sm -space-y-px" >
57
+ < div className = "relative" >
58
+ < FaEnvelope className = "absolute left-3 top-3 text-gray-400" />
59
+ < input
60
+ id = "email-address"
61
+ name = "email"
62
+ type = "email"
63
+ autoComplete = "email"
64
+ required
65
+ className = "appearance-none rounded-none relative block w-full px-10 py-2 border border-gray-600 placeholder-gray-400 text-white bg-gray-900 rounded-t-md focus:outline-none focus:ring-blue-500 focus:border-blue-500 focus:z-10 sm:text-sm"
66
+ placeholder = "Email address"
67
+ value = { email }
68
+ onChange = { ( e ) => setEmail ( e . target . value ) }
69
+ />
77
70
</ div >
78
- < div >
79
- < label htmlFor = "password" className = "sr-only" >
80
- Password
81
- </ label >
82
- < div className = "relative" >
83
- < div className = "absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none" >
84
- < FaLock className = "h-5 w-5 text-gray-400" />
85
- </ div >
86
- < input
87
- id = "password"
88
- name = "password"
89
- type = "password"
90
- autoComplete = "new-password"
91
- required
92
- value = { password }
93
- onChange = { ( e ) => setPassword ( e . target . value ) }
94
- className = "appearance-none relative block w-full px-3 py-2 pl-10 bg-gray-900 border border-gray-600 placeholder-gray-400 text-white rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
95
- placeholder = "Password"
96
- />
97
- </ div >
71
+ < div className = "relative" >
72
+ < FaLock className = "absolute left-3 top-3 text-gray-400" />
73
+ < input
74
+ id = "password"
75
+ name = "password"
76
+ type = "password"
77
+ autoComplete = "new-password"
78
+ required
79
+ className = "appearance-none rounded-none relative block w-full px-10 py-2 border border-gray-600 placeholder-gray-400 text-white bg-gray-900 focus:outline-none focus:ring-blue-500 focus:border-blue-500 focus:z-10 sm:text-sm"
80
+ placeholder = "Password"
81
+ value = { password }
82
+ onChange = { ( e ) => setPassword ( e . target . value ) }
83
+ />
98
84
</ div >
99
- < div >
100
- < label htmlFor = "confirm-password" className = "sr-only" >
101
- Confirm Password
102
- </ label >
103
- < div className = "relative" >
104
- < div className = "absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none" >
105
- < FaLock className = "h-5 w-5 text-gray-400" />
106
- </ div >
107
- < input
108
- id = "confirm-password"
109
- name = "confirm-password"
110
- type = "password"
111
- autoComplete = "new-password"
112
- required
113
- value = { confirmPassword }
114
- onChange = { ( e ) => setConfirmPassword ( e . target . value ) }
115
- className = "appearance-none relative block w-full px-3 py-2 pl-10 bg-gray-900 border border-gray-600 placeholder-gray-400 text-white rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
116
- placeholder = "Confirm password"
117
- />
118
- </ div >
85
+ < div className = "relative" >
86
+ < FaLock className = "absolute left-3 top-3 text-gray-400" />
87
+ < input
88
+ id = "confirm-password"
89
+ name = "confirm-password"
90
+ type = "password"
91
+ autoComplete = "new-password"
92
+ required
93
+ className = "appearance-none rounded-none relative block w-full px-10 py-2 border border-gray-600 placeholder-gray-400 text-white bg-gray-900 rounded-b-md focus:outline-none focus:ring-blue-500 focus:border-blue-500 focus:z-10 sm:text-sm"
94
+ placeholder = "Confirm password"
95
+ value = { confirmPassword }
96
+ onChange = { ( e ) => setConfirmPassword ( e . target . value ) }
97
+ />
119
98
</ div >
120
99
</ div >
121
100
122
101
< div >
123
102
< button
124
103
type = "submit"
125
104
disabled = { loading }
126
- className = "group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-lg text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed "
105
+ className = "group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50"
127
106
>
128
- < span className = "absolute left-0 inset-y-0 flex items-center pl-3" >
129
- < FaUserPlus className = "h-5 w-5 text-blue-500 group-hover:text-blue-400" />
130
- </ span >
131
107
{ loading ? "Creating account..." : "Create account" }
132
108
</ button >
133
109
</ div >
134
110
135
111
< div className = "text-center" >
136
112
< Link
137
- href = " /login"
113
+ href = { ` ${ basePath } /login` }
138
114
className = "font-medium text-blue-400 hover:text-blue-500"
139
115
>
140
- Already have an account? Sign in
116
+ Already have an account? Sign in here
141
117
</ Link >
142
118
</ div >
143
119
</ form >
0 commit comments