Untitled
const handleRegister = async () => { setLoading(true); //initialize formData const formData = new FormData(); //append data to formData formData.append("name", formik.values.name); formData.append("username", formik.values.username); formData.append("email", formik.values.email); formData.append("phone", formik.values.phone); formData.append("address", formik.values.address); formData.append("password", formik.values.password); formData.append( "password_confirmation", formik.values.passwordConfirmation ); try { const response = await axios.post("/register", formData, { headers: { "X-XSRF-TOKEN": Cookies.get("XSRF-TOKEN"), }, }); if (response.status === 201) { myToastSuccess("Register Berhasil"); setLoading(false); const responseUser = await axios.get("/api/me"); if (responseUser.status === 200) { setUser(responseUser.data.data); setIsLogin(true); router.replace("/email-verify"); } else { setIsLogin(false); setLoading(false); } } else { myToastError("Register Gagal"); setLoading(false); } } catch ({ response }) { myToastError("Register Gagal"); formik.setErrors(response.data.errors); setUser({}); setIsLogin(false); setLoading(false); } };
Leave a Comment