Home > Web Front-end > JS Tutorial > Request Aborted (NS_BINDING_ABORT) In Firefox but working in remaining browsers

Request Aborted (NS_BINDING_ABORT) In Firefox but working in remaining browsers

Barbara Streisand
Release: 2024-11-14 15:38:02
Original
571 people have browsed it

Request Aborted (NS_BINDING_ABORT) In Firefox but working in remaining browsers

const Login = () => {

  const { isAuthenticated } = useSelector(

    (rootState: RootState) => rootState.auth

  );

  const router = useRouter();

  const dispatch = useDispatch();

  const searchParams = useSearchParams();

  const [isLoading, setIsLoading] = useState(false);

  const [passwordVisible, setPasswordVisible] = useState(false);

  const togglePasswordVisibility = () => {

    setPasswordVisible(!passwordVisible);

  };

  const ValidationSchema = z.object({

    email: z.string().email("Please enter a valid email address"),

    password: z

      .string()

      .min(8, "Password must be at least 8 characters")

      .max(20, "Password can't exceed 20 characters"),

    remember_me: z.boolean().optional().default(false),

  });

  const [isPending, setIsPending] = useState(false);

  type ValidationSchemaType = z.infer;

  useEffect(() => {

    if (isAuthenticated) {

      router.push("/app");

    }

  }, [isAuthenticated]);

  const {

    watch,

    setValue,

    register,

    handleSubmit,

    formState: { errors },

  } = useForm({

    resolver: zodResolver(ValidationSchema),

  });

  const handleGetProfileData = async () => {

    try {

      const response = await axios.get(${API_URL}/users/api/v1);

      const userData = response?.data?.data;

      return userData;

    } catch (error) {

      console.log(error);

    }

  };

  const onSubmit: SubmitHandler = async data => {

    setIsPending(true);

    try {

      const validatedData = ValidationSchema.parse(data);

      const response = await axios.post(

        API_URL "/users/api/v1/auth/login",

        validatedData

      );

      const expiryTime = watch("remember_me")

        ? 30 * 24 * 60 * 60 * 1000

        : 7 * 24 * 60 * 60 * 1000;

      setCookie("token", response.data.data.token, {

        secure: true,

        sameSite: "none",

        expires: new Date(Date.now() expiryTime),

        // domain: process.env.NEXT_PUBLIC_APP_BASE_URL,

      });

      const userData = await handleGetProfileData();

      dispatch(login(userData));

      router.push("/app");

      toast.success(response.data.message);

    } catch (error: any) {

      if (error.response) {

        toast.error(error.response.data.message);

      } else {

        toast.error(error.message);

      }

      console.error("Login failed:", error);

    } finally {

      setIsPending(false);

    }

  };

return(
//rest of code
);
};

I have written like this for user authentication. But I'm getting error request aborted.
-> I have entered credentials and send to backend.
-> Token is generating and get success message.
-> After that I've to redirect to app page. but while redirecting the request is aborting.

can any one help me in this to solve this issue

The above is the detailed content of Request Aborted (NS_BINDING_ABORT) In Firefox but working in remaining browsers. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template