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 customer login functionality

Implementing customer login functionality

We have created the API for the login functionality in the admin section. Now it's time to implement the login functionality on the client side. So just like we did with signup, we will create a server action for the login functionality. I will navigate to the auth action js file and say export async function login user. Here also we are going to receive the form data. Now I will gather all the data. So const data and e-mail form data dot get e-mail and same for the password. Now let me call the login API. So I'll say const response is equal to await fetch dollar curly brackets. Now I want to use the base URL like we did in signup. So I will make this variable global, that is, shift it outside the function. And now I will give the base URL slash API slash auth slash login. And in the options, I will say method is equal to post headers with content type application json and passing the data using body colon json dot stringify data. Now let's also handle the errors. So again I'll say if…

Contents