@@ -4,21 +4,16 @@ import { toTypedSchema } from '@vee-validate/zod'
44import * as z from ' zod'
55import { ref } from ' vue'
66import { useRouter } from ' vue-router'
7- import { Mail , AlertTriangle , CheckCircle } from ' lucide-vue-next'
7+ import { Mail } from ' lucide-vue-next'
88import { useI18n } from ' vue-i18n'
9+ import { toast } from ' vue-sonner'
910import { UserService } from ' @/services/userService'
1011
1112import {
1213 Card ,
1314 CardContent ,
1415} from ' @/components/ui/card'
1516
16- import {
17- Alert ,
18- AlertDescription ,
19- AlertTitle ,
20- } from ' @/components/ui/alert'
21-
2217import { Button } from ' @/components/ui/button'
2318import {
2419 FormControl ,
@@ -31,8 +26,6 @@ import { Input } from '@/components/ui/input'
3126
3227const router = useRouter ()
3328const isLoading = ref (false )
34- const errorMessage = ref (' ' )
35- const showSuccess = ref (false )
3629const { t } = useI18n ()
3730
3831// Define validation schema using Zod
@@ -52,79 +45,27 @@ const form = useForm({
5245 },
5346})
5447
55- // Clear error when user starts typing
56- const clearError = () => {
57- errorMessage .value = ' '
58- }
59-
60- interface ForgotPasswordError {
61- name? : string ;
62- message? : string ;
63- status? : number ;
64- }
6548
66- interface PotentialError {
67- name? : unknown ;
68- message? : unknown ;
69- status? : unknown ;
70- }
71-
72- // Handle different types of errors
73- const handleError = (error : ForgotPasswordError ) => {
74- if (error .name === ' TypeError' && error .message && error .message .includes (' fetch' )) {
75- // Network error - backend is down
76- errorMessage .value = t (' forgotPassword.errors.networkError' )
77- } else if (error .message === ' SERVICE_UNAVAILABLE' ) {
78- // Service unavailable
79- errorMessage .value = t (' forgotPassword.errors.serviceUnavailable' )
80- } else if (error .status && error .status >= 500 ) {
81- // Server error
82- errorMessage .value = t (' forgotPassword.errors.serverError' )
83- } else if (error .name === ' AbortError' ) {
84- // Request timeout
85- errorMessage .value = t (' forgotPassword.errors.networkError' )
86- } else {
87- // Unknown error
88- errorMessage .value = t (' forgotPassword.errors.unknownError' )
89- }
90- }
9149
9250const onSubmit = form .handleSubmit (async (values ) => {
9351 isLoading .value = true
94- errorMessage .value = ' '
9552
9653 try {
9754 await UserService .requestPasswordReset (values .email )
9855
99- // Always show success message for security (don't reveal if email exists)
100- showSuccess .value = true
101-
102- } catch (e ) {
103- console .error (' Password reset request error:' , e );
104- const errorToHandle: ForgotPasswordError = { message: t (' forgotPassword.errors.unknownError' ) };
105- const potentialError = e as PotentialError ;
106-
107- if (typeof potentialError .name === ' string' ) {
108- errorToHandle .name = potentialError .name ;
109- }
110- if (typeof potentialError .message === ' string' ) {
111- errorToHandle .message = potentialError .message ;
112- }
113- if (typeof potentialError .status === ' number' ) {
114- errorToHandle .status = potentialError .status ;
115- }
116-
117- // If it's a standard Error instance, prefer its properties
118- if (e instanceof Error ) {
119- errorToHandle .name = e .name ;
120- errorToHandle .message = e .message ;
121- }
122-
123- // Ensure message is always set if not already by previous checks
124- if (! errorToHandle .message ) {
125- errorToHandle .message = t (' forgotPassword.errors.unknownError' );
126- }
127- handleError (errorToHandle );
56+ // Show success toast and redirect to login
57+ toast .success (' Check your mailbox to reset password' )
58+
59+ // Redirect to login page
60+ router .push (' /login' )
61+
62+ } catch (error ) {
63+ console .error (' Password reset request error:' , error )
64+
65+ // Show error toast
66+ toast .error (t (' forgotPassword.errors.title' ), {
67+ description: t (' forgotPassword.errors.unknownError' )
68+ })
12869 } finally {
12970 isLoading .value = false
13071 }
@@ -152,28 +93,7 @@ const navigateToLogin = () => {
15293 </div >
15394
15495 <div class =" mt-10 sm:mx-auto sm:w-full sm:max-w-sm" >
155- <!-- Success Alert -->
156- <Alert v-if =" showSuccess" class =" mb-6" >
157- <CheckCircle class =" h-4 w-4" />
158- <AlertTitle >{{ $t('forgotPassword.success.title') }}</AlertTitle >
159- <AlertDescription >
160- <div class =" space-y-2" >
161- <p >{{ $t('forgotPassword.success.message') }}</p >
162- <p class =" text-sm" >{{ $t('forgotPassword.success.instruction') }}</p >
163- </div >
164- </AlertDescription >
165- </Alert >
166-
167- <!-- Error Alert -->
168- <Alert v-if =" errorMessage" variant =" destructive" class =" mb-6" >
169- <AlertTriangle class =" h-4 w-4" />
170- <AlertTitle >{{ $t('forgotPassword.errors.title') }}</AlertTitle >
171- <AlertDescription >
172- {{ errorMessage }}
173- </AlertDescription >
174- </Alert >
175-
176- <Card v-if =" !showSuccess" >
96+ <Card >
17797 <CardContent class =" pt-6" >
17898 <form @submit =" onSubmit" class =" space-y-6" >
17999 <FormField v-slot =" { componentField }" name =" email" >
@@ -188,7 +108,6 @@ const navigateToLogin = () => {
188108 v-bind =" componentField"
189109 class =" pl-10"
190110 autocomplete =" email"
191- @input =" clearError"
192111 />
193112 </div >
194113 </FormControl >
0 commit comments