Next.js Discord

Discord Forum

Async function stopped working (inside form onSubmit)

Unanswered
Bigeye scad posted this in #help-forum
Open in Discord
Bigeye scadOP
I have a simple login form using nextjs and react-hook-form. In the on submit function, I call a server action. It has been working perfectly, but all of a sudden I get this error when trying to submit

Uncaught (in promise) SyntaxError: await is only valid in async functions and the top level bodies of modules


I dont understand why I am getting this error all of a sudden. Here is the code

All my other server actions being called from the client are also not working?
Nextjs 14.2.5

2 Replies

Bigeye scadOP
I have another project where this code works absolutely fine....
Sun bear
this should work lol. maybe try using the function syntax:

async function onSubmit(values) {
  const result = await login(values)
  // ... code
}


also the react-hook-form docs do it a little different so maybe try that:

https://react-hook-form.com/ts