Next.js Discord

Discord Forum

Next-auth is not automatically logging out the user if I get 401.

Unanswered
Cape horse mackerel posted this in #help-forum
Open in Discord
Cape horse mackerelOP
So, the token is obviously expired or it's wrong and my API returns me 401
but next-auth is not automatically logging out the user.
I mean, should the next-auth do that or I should do it in another way?
I have refetchInterval set and also maxAge for JWT
but the session is being refreshed and the token that I get in the session is wrong one

3 Replies

Can you try downgrading next-auth or nextjs version? I see few people facing the same issue
Cape horse mackerelOP
I'm using "next-auth": "4.24.6",
This is how my auth.ts looks like
// auth.ts
function getSecondsFromNowToMidnight(): number {
  const currentDate = new Date();
  const currentTime = currentDate.getTime();
  const midnightTime = currentDate.setHours(23, 59, 59, 999);
  return Math.ceil((midnightTime - currentTime) / 1000);
}

{
//...the rest is omitted...
   jwt: {
    maxAge: secondsFromNowToMidnight,
  },
   session: {
    maxAge: secondsFromNowToMidnight,
    strategy: "jwt",
  },
}