Next.js Discord

Discord Forum

Authentication with Cookies

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
Hello all,
I am new to NextJS. I tried to implement authentication using cookies and I am facing some issues with the implementation. I have set the authentication cookie to expire in 30 seconds for testing.
Issue:
1. Once I login, I set the authentication cookies via api route and redirect to a protected route ("/list-meeting") in client component using useRouter from "next/navigation"
2. I wait for 30 seconds and then click on a button with next/link to another protected route ("/create-meeting"). Middleware then redirects me to login page.
3. After I login, I am again redirected to "list-meeting", which is a client component
4. Now when I click on next/link before the token expiry, I am redirected to "login" page.

I can't access the "create-meeting" page until I reload the page.

Let me know what I need to add for better understanding.

4 Replies