recoverPasswordAction.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use server";
  2. import {FORGET_PASSWORD} from "@/graphql/customer/mutations";
  3. import { serverGraphqlFetch } from "@utils/bagisto";
  4. interface ForgetPasswordData{
  5. createForgotPassword: {
  6. forgotPassword: {
  7. success: boolean;
  8. message: string;
  9. }
  10. }
  11. }
  12. export async function recoverPasswordAction(formData: {
  13. email: string;
  14. }): Promise<{ success: boolean; msg: string;}> {
  15. try {
  16. const response = await serverGraphqlFetch<ForgetPasswordData,{email: string;}>({
  17. query: FORGET_PASSWORD,
  18. variables: {
  19. email: formData.email
  20. }
  21. });
  22. if(!response.error) {
  23. const resData = response?.data?.createForgotPassword?.forgotPassword;
  24. return {
  25. success: resData?.success ?? false,
  26. msg: resData?.message ?? '',
  27. };
  28. } else {
  29. return {
  30. success: false,
  31. msg: response.error.message,
  32. }
  33. }
  34. } catch(error) {
  35. return {
  36. success: false,
  37. msg: error instanceof Error ? error.message : 'Add product to cart failed!',
  38. }
  39. }
  40. }