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.

Authenticate all the server actions of admin section

Authenticate all the server actions of admin section

In this lecture, we will complete the final step for setting up security and authentication in the admin app. In this step, we will place a token verification check before executing every server action to ensure that only authenticated users can perform operations. For this, we will execute the JWT token verification function before executing any of the server actions. So I'll open the product actions.js file. And verify the user before executing the create product server action by saying await JWT token verification. Now I will copy this function and paste it in all the server actions of that file. Alright, now I will do the same thing in the product type actions.js file as well. And finally for user actions.js file. Alright, now we will verify this functionality. So I will simulate a situation where the token gets timed out after getting logged in and then we will try to execute an action. So let me open the utils.js file and set the expiry time of the token to 15 seconds. Let's…

Contents