Implement Fauna Signin with Next.js Server Actions and useFormState React Hook

Share this video with your friends

Send Tweet

For user signin, we'll implement a proper server action by creating a actions.js file where our server actions can live. In our login page, we'll set the component to be a client component to hold some state. This way we can use the new useFormState hook from react-dom and pass in our login server action.

Within the action we'll call our UserLogin function from Fauna and set a cookie with the secret we get back that we can use throughout our application.