From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Implementing sign-up functionality in the client section

Implementing sign-up functionality in the client section

We have created the API for the signup functionality in the admin section. Now we will implement the signup functionality on the client side. And we will create a server action for calling the API and handling the form submission. So I will create a file called AuthActionsJS inside the actions directory. it I will say export async function register user and will receive the form data here. Now I will gather all the data in a constant so I'll say const data is equal to name colon form data dot get name and now similarly I'll get the e-mail and the password. Now let me create the base URL variable for the registerUser function. So I'll say const baseUrl is equal to process.env.nextPublicBaseUrl. Now let me call the signup API. I will say const response is equal to await fetch $baseurl slash api slash auth slash signup with method post headers with content type application json and pass the data using body json.stringify and will pass the data. Next I will handle the error by writing if…

Contents