@@ -26,43 +26,27 @@ export function SignInModal({
26
26
const router = useRouter ( ) ;
27
27
const [ email , setEmail ] = useState ( '' ) ;
28
28
const [ password , setPassword ] = useState ( '' ) ;
29
- const [ showPassword , setShowPassword ] = useState ( false ) ;
29
+ const [ errorMessage , setErrorMessage ] = useState < string | null > ( null ) ; // ✅ State for error message
30
30
31
31
const [ loginUser , { loading } ] = useMutation ( LOGIN_USER , {
32
32
onCompleted : ( data ) => {
33
33
if ( data ?. login ) {
34
- // Store tokens
35
34
localStorage . setItem ( 'accessToken' , data . login . accessToken ) ;
36
35
localStorage . setItem ( 'refreshToken' , data . login . refreshToken ) ;
37
-
38
- // Show success message
39
36
toast . success ( 'Login successful!' ) ;
40
-
41
- // Close the modal
37
+ setErrorMessage ( null ) ; // ✅ Clear error on success
42
38
onClose ( ) ;
43
-
44
-
45
- router . push ( '/main/chat' ) ;
39
+ router . push ( '/x' ) ;
46
40
}
47
41
} ,
48
42
onError : ( error ) => {
49
- toast . error ( error . message ) ;
43
+ setErrorMessage ( 'Incorrect email or password. Please try again.' ) ; // ✅ Show error message
50
44
} ,
51
45
} ) ;
52
46
53
- const handleEmailSubmit = ( e : React . FormEvent ) => {
54
- e . preventDefault ( ) ;
55
- setPassword ( '' ) ; // Clear password when moving to password step
56
- setShowPassword ( true ) ;
57
- } ;
58
-
59
- const handleBackToEmail = ( ) => {
60
- setPassword ( '' ) ; // Clear password when going back
61
- setShowPassword ( false ) ;
62
- } ;
63
-
64
47
const handleSubmit = async ( e : React . FormEvent ) => {
65
48
e . preventDefault ( ) ;
49
+ setErrorMessage ( null ) ; // ✅ Clear error when attempting login again
66
50
try {
67
51
await loginUser ( {
68
52
variables : {
@@ -85,96 +69,88 @@ export function SignInModal({
85
69
< TextureCardHeader className = "flex flex-col gap-1 items-center justify-center p-4" >
86
70
< TextureCardTitle > Welcome back</ TextureCardTitle >
87
71
< p className = "text-center text-neutral-600 dark:text-neutral-400" >
88
- { showPassword
89
- ? 'Enter your password'
90
- : 'Sign in to your account' }
72
+ Sign in to your account
91
73
</ p >
92
74
</ TextureCardHeader >
93
75
< TextureSeparator />
94
76
< TextureCardContent >
95
- { ! showPassword ? (
96
- < >
97
- < form onSubmit = { handleEmailSubmit } className = "space-y-4" >
98
- < div >
99
- < Label htmlFor = "email" > Email</ Label >
100
- < Input
101
- id = "email"
102
- type = "email"
103
- value = { email }
104
- onChange = { ( e ) => setEmail ( e . target . value ) }
105
- required
106
- className = "w-full px-4 py-2 rounded-md border"
107
- />
108
- </ div >
109
- < Button type = "submit" className = "w-full" >
110
- Continue
111
- </ Button >
112
- </ form >
77
+ < form onSubmit = { handleSubmit } className = "space-y-4" >
78
+ < div >
79
+ < Label htmlFor = "email" > Email</ Label >
80
+ < Input
81
+ id = "email"
82
+ type = "email"
83
+ value = { email }
84
+ onChange = { ( e ) => {
85
+ setEmail ( e . target . value ) ;
86
+ setErrorMessage ( null ) ; // ✅ Clear error when user types
87
+ } }
88
+ required
89
+ className = "w-full px-4 py-2 rounded-md border"
90
+ />
91
+ </ div >
92
+ < div >
93
+ < Label htmlFor = "password" > Password</ Label >
94
+ < Input
95
+ id = "password"
96
+ type = "password"
97
+ value = { password }
98
+ onChange = { ( e ) => {
99
+ setPassword ( e . target . value ) ;
100
+ setErrorMessage ( null ) ; // ✅ Clear error when user types
101
+ } }
102
+ required
103
+ className = "w-full px-4 py-2 rounded-md border"
104
+ />
105
+ </ div >
106
+
107
+ { /* ✅ Show error message if login fails */ }
108
+ { errorMessage && (
109
+ < div className = "text-red-500 text-sm text-center" > { errorMessage } </ div >
110
+ ) }
113
111
114
- < div className = "mt-6" >
115
- < div className = "relative" >
116
- < div className = "absolute inset-0 flex items-center" >
117
- < span className = "w-full border-t" />
118
- </ div >
119
- < div className = "relative flex justify-center text-xs uppercase" >
120
- < span className = "bg-white dark:bg-zinc-900 px-2 text-muted-foreground" >
121
- Or continue with
122
- </ span >
123
- </ div >
124
- </ div >
112
+ < Button type = "submit" className = "w-full" disabled = { loading } >
113
+ { loading ? 'Signing in...' : 'Sign in' }
114
+ </ Button >
115
+ </ form >
125
116
126
- < div className = "mt-4 flex flex-col gap-4" >
127
- < Button
128
- variant = "outline"
129
- className = "flex items-center gap-2 w-full"
130
- >
131
- < img
132
- src = "/images/google.png"
133
- alt = "Google"
134
- className = "w-5 h-5"
135
- />
136
- < span > Google</ span >
137
- </ Button >
138
- < Button
139
- variant = "outline"
140
- className = "flex items-center gap-2 w-full"
141
- >
142
- < img
143
- src = "/images/github.png"
144
- alt = "GitHub"
145
- className = "w-5 h-5"
146
- />
147
- < span > GitHub</ span >
148
- </ Button >
149
- </ div >
117
+ < div className = "mt-6" >
118
+ < div className = "relative" >
119
+ < div className = "absolute inset-0 flex items-center" >
120
+ < span className = "w-full border-t" />
150
121
</ div >
151
- </ >
152
- ) : (
153
- < form onSubmit = { handleSubmit } className = "space-y-4" >
154
- < div >
155
- < Label htmlFor = "password" > Password</ Label >
156
- < Input
157
- id = "password"
158
- type = "password"
159
- value = { password }
160
- onChange = { ( e ) => setPassword ( e . target . value ) }
161
- required
162
- className = "w-full px-4 py-2 rounded-md border"
163
- />
122
+ < div className = "relative flex justify-center text-xs uppercase" >
123
+ < span className = "bg-white dark:bg-zinc-900 px-2 text-muted-foreground" >
124
+ Or continue with
125
+ </ span >
164
126
</ div >
165
- < Button type = "submit" className = "w-full" >
166
- Sign in
127
+ </ div >
128
+
129
+ < div className = "mt-4 flex flex-col gap-4" >
130
+ < Button
131
+ variant = "outline"
132
+ className = "flex items-center gap-2 w-full"
133
+ >
134
+ < img
135
+ src = "/images/google.png"
136
+ alt = "Google"
137
+ className = "w-5 h-5"
138
+ />
139
+ < span > Google</ span >
167
140
</ Button >
168
141
< Button
169
- type = "button"
170
- variant = "link"
171
- onClick = { handleBackToEmail }
172
- className = "w-full"
142
+ variant = "outline"
143
+ className = "flex items-center gap-2 w-full"
173
144
>
174
- Back to email
145
+ < img
146
+ src = "/images/github.png"
147
+ alt = "GitHub"
148
+ className = "w-5 h-5"
149
+ />
150
+ < span > GitHub</ span >
175
151
</ Button >
176
- </ form >
177
- ) }
152
+ </ div >
153
+ </ div >
178
154
</ TextureCardContent >
179
155
</ div >
180
156
</ BackgroundGradient >
0 commit comments