Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

The following field is invalid: password at generatePasswordSaltHash

default discord avatar
_thaotruong2 years ago
4

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
    notchr2 years ago

    Hello

    @546799426895872000

    - do you mind posting your user creation logic?



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

  • default discord avatar
    _thaotruong2 years 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]


    );



    @1049775120559898725

    above is my code to create a user on FE

  • default discord avatar
    notchr2 years ago
    @546799426895872000

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

  • default discord avatar
    _thaotruong2 years ago
    @1049775120559898725

    thanks for pointing that out. That explains

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.