@@ -53,8 +53,11 @@ const SignUp: React.FC = () => {
5353 if ( name === "password" ) {
5454 if ( ! value . trim ( ) ) {
5555 errorMessage = "Password is required" ;
56- } else if ( ! / ^ (? = .* [ A - Z a - z ] ) (? = .* \d ) [ A - Z a - z \d @ $ ! % * # ? & ] { 8 , } $ / . test ( value ) ) {
57- errorMessage = "Password must be 8+ characters with letters and numbers" ;
56+ } else if (
57+ ! / ^ (? = .* [ A - Z a - z ] ) (? = .* \d ) [ A - Z a - z \d @ $ ! % * # ? & ] { 8 , } $ / . test ( value )
58+ ) {
59+ errorMessage =
60+ "Password must be 8+ characters with letters and numbers" ;
5861 }
5962 }
6063 setErrors ( ( prev ) => ( { ...prev , [ name ] : errorMessage } ) ) ;
@@ -65,35 +68,49 @@ const SignUp: React.FC = () => {
6568 const usernameError = ! formData . username . trim ( )
6669 ? "Username is required"
6770 : ! / ^ [ A - Z a - z \s ] + $ / . test ( formData . username )
68- ? "Only letters are allowed"
69- : "" ;
71+ ? "Only letters are allowed"
72+ : "" ;
7073 const emailError = ! formData . email . trim ( )
7174 ? "Email is required"
7275 : ! / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / . test ( formData . email . trim ( ) )
73- ? "Enter a valid email"
74- : "" ;
76+ ? "Enter a valid email"
77+ : "" ;
7578 const passwordError = ! formData . password . trim ( )
7679 ? "Password is required"
77- : ! / ^ (? = .* [ A - Z a - z ] ) (? = .* \d ) [ A - Z a - z \d @ $ ! % * # ? & ] { 8 , } $ / . test ( formData . password )
78- ? "Password must be 8+ characters with letters and numbers"
79- : "" ;
80+ : ! / ^ (? = .* [ A - Z a - z ] ) (? = .* \d ) [ A - Z a - z \d @ $ ! % * # ? & ] { 8 , } $ / . test (
81+ formData . password ,
82+ )
83+ ? "Password must be 8+ characters with letters and numbers"
84+ : "" ;
8085 if ( usernameError || emailError || passwordError ) {
81- setErrors ( { username : usernameError , email : emailError , password : passwordError } ) ;
86+ setErrors ( {
87+ username : usernameError ,
88+ email : emailError ,
89+ password : passwordError ,
90+ } ) ;
8291 return ;
8392 }
8493 setIsLoading ( true ) ;
8594 try {
86- const response = await axios . post ( `${ backendUrl } /api/auth/signup` ,
87- formData // Include cookies for session
95+ const response = await axios . post (
96+ `${ backendUrl } /api/auth/signup` ,
97+ formData , // Include cookies for session
8898 ) ;
8999 setMessage ( response . data . message ) ; // Show success message from backend
90100
91101 // Navigate to login page after successful signup
92- if ( response . data . message === ' User created successfully' ) {
102+ if ( response . data . message === " User created successfully" ) {
93103 navigate ( "/login" ) ;
94104 }
95- } catch ( error : any ) {
96- setMessage ( error . response ?. data ?. message || "Something went wrong. Please try again." ) ;
105+ } catch ( error : unknown ) {
106+ if ( axios . isAxiosError ( error ) ) {
107+ setMessage (
108+ error . response ?. data ?. message ||
109+ "Something went wrong. Please try again." ,
110+ ) ;
111+ } else {
112+ setMessage ( "Something went wrong. Please try again." ) ;
113+ }
97114 } finally {
98115 setIsLoading ( false ) ;
99116 }
@@ -138,10 +155,22 @@ const SignUp: React.FC = () => {
138155 className = "text-center mb-10"
139156 >
140157 < div className = "inline-flex items-center justify-center w-20 h-20 bg-white rounded-3xl mb-6 shadow-2xl transform hover:scale-105 transition-transform duration-300 overflow-hidden" >
141- < img src = "/crl-icon.png" alt = "Logo" className = "w-14 h-14 object-contain" />
158+ < img
159+ src = "/crl-icon.png"
160+ alt = "Logo"
161+ className = "w-14 h-14 object-contain"
162+ />
142163 </ div >
143- < h1 className = { `text-4xl font-bold mb-2 ${ mode === "dark" ? "text-white" : "text-black" } ` } > GitHubTracker</ h1 >
144- < p className = { `text-lg font-medium ${ mode === "dark" ? "text-slate-300" : "text-gray-700" } ` } > Join your GitHub journey</ p >
164+ < h1
165+ className = { `text-4xl font-bold mb-2 ${ mode === "dark" ? "text-white" : "text-black" } ` }
166+ >
167+ GitHubTracker
168+ </ h1 >
169+ < p
170+ className = { `text-lg font-medium ${ mode === "dark" ? "text-slate-300" : "text-gray-700" } ` }
171+ >
172+ Join your GitHub journey
173+ </ p >
145174 </ motion . div >
146175
147176 < motion . div
@@ -154,7 +183,6 @@ const SignUp: React.FC = () => {
154183 : "bg-white border-gray-200 text-black"
155184 } `}
156185 >
157-
158186 < h2
159187 className = { `text-2xl font-bold text-center mb-8 ${
160188 mode === "dark" ? "text-white" : "text-gray-800"
@@ -170,18 +198,19 @@ const SignUp: React.FC = () => {
170198 < div className = "absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none" >
171199 < User className = "h-5 w-5 text-gray-400" />
172200 </ div >
173- < input
174- id = "username"
175- type = "text"
176- name = "username"
177- placeholder = "Enter your username"
178- value = { formData . username }
179- onChange = { handleChange }
201+ < input
202+ type = "text"
203+ name = "username"
204+ placeholder = "Enter your username"
205+ value = { formData . username }
206+ onChange = { handleChange }
180207 required
181208 className = { `w-full pl-12 pr-4 py-4 rounded-2xl border focus:outline-none focus:ring-2 focus:ring-gray-400 focus:border-transparent transition-all duration-300 ${ mode === "dark" ? "bg-white/10 border-white/20 text-white placeholder-gray-400" : "bg-gray-100 border-gray-300 text-black placeholder-gray-400" } ` }
182209 />
183210 </ div >
184- { errors . username && < p className = "text-red-500 text-sm mt-2" > { errors . username } </ p > }
211+ { errors . username && (
212+ < p className = "text-red-500 text-sm mt-2" > { errors . username } </ p >
213+ ) }
185214 </ div >
186215
187216 < div >
@@ -190,18 +219,19 @@ const SignUp: React.FC = () => {
190219 < div className = "absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none" >
191220 < Mail className = "h-5 w-5 text-gray-400" />
192221 </ div >
193- < input
194- id = "email"
195- type = "email"
196- name = "email"
197- placeholder = "Enter your email"
198- value = { formData . email }
199- onChange = { handleChange }
222+ < input
223+ type = "email"
224+ name = "email"
225+ placeholder = "Enter your email"
226+ value = { formData . email }
227+ onChange = { handleChange }
200228 required
201229 className = { `w-full pl-12 pr-4 py-4 rounded-2xl border focus:outline-none focus:ring-2 focus:ring-gray-400 focus:border-transparent transition-all duration-300 ${ mode === "dark" ? "bg-white/10 border-white/20 text-white placeholder-gray-400" : "bg-gray-100 border-gray-300 text-black placeholder-gray-400" } ` }
202230 />
203231 </ div >
204- { errors . email && < p className = "text-red-500 text-sm mt-2" > { errors . email } </ p > }
232+ { errors . email && (
233+ < p className = "text-red-500 text-sm mt-2" > { errors . email } </ p >
234+ ) }
205235 </ div >
206236
207237 < div >
@@ -210,26 +240,32 @@ const SignUp: React.FC = () => {
210240 < div className = "absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none" >
211241 < Lock className = "h-5 w-5 text-gray-400" />
212242 </ div >
213- < input
214- id = "password"
215- type = { showPassword ? "text" : "password" }
216- name = "password"
217- placeholder = "Enter your password"
218- value = { formData . password }
219- onChange = { handleChange }
243+ < input
244+ type = { showPassword ? "text" : "password" }
245+ name = "password"
246+ placeholder = "Enter your password"
247+ value = { formData . password }
248+ onChange = { handleChange }
220249 required
221250 className = { `w-full pl-12 pr-12 py-4 rounded-2xl border focus:outline-none focus:ring-2 focus:ring-gray-400 focus:border-transparent transition-all duration-300 ${ mode === "dark" ? "bg-white/10 border-white/20 text-white placeholder-gray-400" : "bg-gray-100 border-gray-300 text-black placeholder-gray-400" } ` }
222251 />
223- < button
224- type = "button"
225- onClick = { ( ) => setShowPassword ( ! showPassword ) }
226- aria-label = { showPassword ? "Hide password" : "Show password" }
252+ < button
253+ type = "button"
254+ onClick = { ( ) => setShowPassword ( ! showPassword ) }
255+ aria-label = { showPassword ? "Hide password" : "Show password" }
227256 aria-pressed = { showPassword }
228- className = { `absolute inset-y-0 right-0 pr-4 flex items-center transition-colors duration-200 ${ mode === "dark" ? "text-slate-400 hover:text-white" : "text-gray-500 hover:text-gray-800" } ` } >
229- { showPassword ? < EyeOff className = "h-5 w-5" /> : < Eye className = "h-5 w-5" /> }
257+ className = { `absolute inset-y-0 right-0 pr-4 flex items-center transition-colors duration-200 ${ mode === "dark" ? "text-slate-400 hover:text-white" : "text-gray-500 hover:text-gray-800" } ` }
258+ >
259+ { showPassword ? (
260+ < EyeOff className = "h-5 w-5" />
261+ ) : (
262+ < Eye className = "h-5 w-5" />
263+ ) }
230264 </ button >
231265 </ div >
232- { errors . password && < p className = "text-red-500 text-sm mt-2" > { errors . password } </ p > }
266+ { errors . password && (
267+ < p className = "text-red-500 text-sm mt-2" > { errors . password } </ p >
268+ ) }
233269 </ div >
234270
235271 < button
@@ -242,15 +278,20 @@ const SignUp: React.FC = () => {
242278 </ form >
243279
244280 { message && (
245- < div className = { `text-center mt-6 p-3 rounded-xl ${ message . includes ( "successfully" ) ? "text-green-600 bg-green-100" : "text-red-600 bg-red-100" } ` } >
281+ < div
282+ className = { `text-center mt-6 p-3 rounded-xl ${ message . includes ( "successfully" ) ? "text-green-600 bg-green-100" : "text-red-600 bg-red-100" } ` }
283+ >
246284 { message }
247285 </ div >
248286 ) }
249287
250288 < div className = "text-center mt-8" >
251289 < p className = { mode === "dark" ? "text-gray-300" : "text-gray-600" } >
252290 Already have an account?{ " " }
253- < Link to = "/login" className = { `font-medium hover:underline transition-colors duration-300 ${ mode === "dark" ? "text-white" : "text-black" } ` } >
291+ < Link
292+ to = "/login"
293+ className = { `font-medium hover:underline transition-colors duration-300 ${ mode === "dark" ? "text-white" : "text-black" } ` }
294+ >
254295 Sign in here
255296 </ Link >
256297 </ p >
0 commit comments