@@ -174,4 +174,76 @@ export class UserService {
174174 this . clearCache ( ) ;
175175 }
176176 }
177+
178+ /**
179+ * Request password reset for email users
180+ */
181+ static async requestPasswordReset ( email : string ) : Promise < { success : boolean ; message : string } > {
182+ try {
183+ const apiUrl = this . getApiUrl ( ) ;
184+ const response = await fetch ( `${ apiUrl } /api/auth/email/forgot-password` , {
185+ method : 'POST' ,
186+ headers : {
187+ 'Content-Type' : 'application/json' ,
188+ } ,
189+ credentials : 'include' ,
190+ body : JSON . stringify ( { email } ) ,
191+ } ) ;
192+
193+ const data = await response . json ( ) ;
194+
195+ if ( response . ok ) {
196+ return data ;
197+ }
198+
199+ // Handle different error status codes
200+ if ( response . status === 503 ) {
201+ throw new Error ( 'SERVICE_UNAVAILABLE' ) ;
202+ }
203+
204+ throw new Error ( `Password reset request failed with status: ${ response . status } ` ) ;
205+ } catch ( error ) {
206+ console . error ( 'Password reset request error:' , error ) ;
207+ throw error ;
208+ }
209+ }
210+
211+ /**
212+ * Reset password using token
213+ */
214+ static async resetPassword ( token : string , newPassword : string ) : Promise < { success : boolean ; message : string } > {
215+ try {
216+ const apiUrl = this . getApiUrl ( ) ;
217+ const response = await fetch ( `${ apiUrl } /api/auth/email/reset-password` , {
218+ method : 'POST' ,
219+ headers : {
220+ 'Content-Type' : 'application/json' ,
221+ } ,
222+ credentials : 'include' ,
223+ body : JSON . stringify ( { token, new_password : newPassword } ) ,
224+ } ) ;
225+
226+ const data = await response . json ( ) ;
227+
228+ if ( response . ok ) {
229+ return data ;
230+ }
231+
232+ // Handle different error status codes
233+ if ( response . status === 400 ) {
234+ throw new Error ( 'INVALID_TOKEN' ) ;
235+ }
236+ if ( response . status === 403 ) {
237+ throw new Error ( 'FORBIDDEN' ) ;
238+ }
239+ if ( response . status === 503 ) {
240+ throw new Error ( 'SERVICE_UNAVAILABLE' ) ;
241+ }
242+
243+ throw new Error ( `Password reset failed with status: ${ response . status } ` ) ;
244+ } catch ( error ) {
245+ console . error ( 'Password reset error:' , error ) ;
246+ throw error ;
247+ }
248+ }
177249}
0 commit comments