Hi all!
I’m playing around with authentication and I’ve noticed a weird behavior in my registration function.
When posting the request for the registration endpoint, the user account does get created, but I get an error Email already taken
, even though there is no user with that email. If that was the case, the error would be Email is already taken
.
Below is my code. The fields language, country and currency are relational fields and trying registration takes 3 seconds. If I don’t send any values for these relational fields in the post request, the registration is quicker / the error appears faster. Is that normal?
// in Next.js: /pages/api/auth/register.js
export default async (req, res) => {
const {email, password, username, language, country, currency} = req.body;
if (req.method === "POST") {
const response = await axios.post(`${API_URL}/api/auth/local/register`,{
email, password, username, language, country, currency
})
.then((response)=> {
return res.status(200).json({message: "Check your email and confirm the registration"})
})
.catch((error)=> {
if (!error.response.data.error.message) {
return res.status(500).json({message: "Internal server error"})
} else {
const msg = error.response.data.error.message;
return res.status(403).json({message: msg})
}
})
}
}
So, why do I get the error Email already taken
upon registering and is it normal that registration takes longer if you set relations?
Running Strapi locally.
Appreciate any help, thanks!