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.

Logout functionality in the client section

Logout functionality in the client section

In this lecture, we will implement the logout functionality. So when the user clicks on the logout option inside the drop down, the user will be logged out and we will achieve this using a server action. So I will open the auth actions JS file and creating a server action by saying export async function logout user. Now I will delete the token from the cookie by saying await delete cookie customer JWT token. Now let me save the code and open the header component. And I will call this server action on click of the logout option in the profile drop down. So I will create a function called const handleLogout, async, then await logoutUser. Then I will reset the state using setCustomerData and will close the drop down. Now let's pass the function to the onClick event of the logout option. I'll say onClick handleLogout. Let's save the code and open the browser. I'll submit the login form with valid credentials. So now we have logged in. Now I will click on the user icon in the header and…

Contents