Hi team,
I create a simple form (email, password field) on nextjs to create a user via restApi like this example
https://payloadcms.com/blog/nextjs-payload-cms-auth. however i get this error 'ValidationError: The following field is invalid: password at generatePasswordSaltHash' when fetch data to '/api/users'. Strangely, when i tried to create a user via Postman, it worked. I'm not sure how to fix this issue. Could you please give me some advice?
Hello @_thaotruong - do you mind posting your user creation logic?
I see the example on the nextjs article, I want to compare
const onSubmit = useCallback(
async (data: FormData) => {
console.log(JSON.stringify(data));
const response = await fetch(
${process.env.NEXT_PUBLIC_CMS_URL}/api/users
,
{
method: "POST",
body: JSON.stringify(data),
mode: "no-cors",
headers: {
"Content-Type": "application/json",
},
}
);
if (response.ok) {
// Set success message for user
setSuccess(true);
// Clear any existing errors
setError("");
} else {
console.log('error', response);
setError(
"There was a problem creating your account. Please try again later."
);
}
},
[login]
);
@notchr above is my code to create a user on FE
@_thaotruong Hmm, is the no-cors portion necessary? Did you set CORS/CSRF listings in your main config?
@notchr thanks for pointing that out. That explains
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.