The following field is invalid: password at generatePasswordSaltHash

default discord avatar
_thaotruong
3 months ago
6

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?

  • default discord avatar
    notchr
    3 months ago

    Hello @_thaotruong - do you mind posting your user creation logic?



    I see the example on the nextjs article, I want to compare

  • default discord avatar
    _thaotruong
    3 months ago

    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

  • default discord avatar
    notchr
    3 months ago

    @_thaotruong Hmm, is the no-cors portion necessary? Did you set CORS/CSRF listings in your main config?

  • default discord avatar
    _thaotruong
    3 months ago

    @notchr thanks for pointing that out. That explains

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.