middleware does not detect the session
Question 💬
when changing the max age of the jwt token in the next auth configs, this results in the middleware not detecting that the user has logged in so that the middleware redirects the user back to the login page while the login page redirects the user to the page protected by the middleware, namely the dashboard page. this cycle occurs repeatedly and continuously, causing the browser to stop.
why this occurs?
How to reproduce ☕️
to try it clone the github repository at here after that
npm install
npm run dev
then go to http://localhost:3000/auth/signin then click the sign in to your account button
below is the code that makes the problem which is part of the next auth config, when I delete the code the middleware works normally. even though the code only changes the exp time of the jwt token. I have created a github repository to produce the error. the code that causes the problem is in the src/lib/session.ts folder
jwt: {
encode: ({ secret, token }) => {
const encodedToken = jsonwebtoken.sign(
{
...token,
exp: Math.floor(Date.now() / 1000) + 60 * 60,
},
secret
);
return encodedToken;
},
decode: async ({ secret, token }) => {
const decodedToken = jsonwebtoken.verify(token!, secret);
return decodedToken as JWT;
},
},
Contributing 🙌🏽
No, I am afraid I cannot help regarding this