I have in an onSubmit function that has the request that handles the user registration and the email sending
const fullData = {
...data,
role: 1,
email: data.email,
password,
username: data.name,
phone: data.Tel,
cabinetName: data.nom_cabinet,
siretNumber: data.siret,
location: [
{
Address: data.Adresse,
Office: data.bureau,
zipCode: data.Code_postal,
city: selectedCityName,
department: data.departement,
country: Country.getCountryByCode(selectedCountryIsoCode as string)
?.name,
State: selectedState?.name, // Use state name here
},
],
};
if (!password) {
setError("Missing password");
setIsLoading(false);
return;
}
setTimeout(async () => {
try {
const strapiResponse = await axios.post(
"http://localhost:1337/api/auth/send-email-confirmation",
{
email,
},
{
headers: {
"Content-Type": "application/json",
},
}
);
console.log("Strapi response:", strapiResponse);
} catch (error) {
console.error("Error sending email confirmation:", error);
}
}, 2000);
try {
const response = await axios.post(
"http://localhost:1337/api/auth/local/register",
fullData
);
setToken(response.data.jwt);
setUser(response.data.user);
} catch (err) {
if (err instanceof AxiosError && err.response) {
setError(err.response.data.error.message);
} else {
setError("Registration failed. Please check the server logs.");
}
setIsLoading(false);
return;
}
navigate("/cabinet"); // Navigate to the dashboard or another route
setIsLoading(false);