Next.js Discord

Discord Forum

Token Expiry Not Updating on getServerSession

Unanswered
Standard Chinchilla posted this in #help-forum
Open in Discord
Standard ChinchillaOP
I am using jwt strategy with next auth.
Making the session works fine and I see that the session 'expires' key gets updated everytime I call getServerSession, but the problem is the token 'exp' key does not get updated everytime I call getServerSession. So lets say the maxAge of my session is 60 sec. Everytime I call getServerSession the expiry pushes for the session by 60 sec, but not for the token. So after one minute of sign in the user is forced to log in even though they didn't have an idle session for longer than 60s due to the token exp

3 Replies

Standard ChinchillaOP
const authOptions = {
  providers: [...],
  session: {
    strategy: "jwt",
    maxAge: 30, // 30 seconds for testing
  },
  callbacks: {
    async jwt({ token, account }) {
      if (!token.account) {
        const user = await prisma.account.findUnique({
          where: {
            email: token.email || "",
          },
        });

        token.account = user;
      }

      return token;
    },
    async session({ session, token }) {
      if (session.user) {
        session.account = token.account as Account;
      }

      console.log({ session, token });
      return session;
    },
  },
}
Standard ChinchillaOP
bump
Standard ChinchillaOP
bump