title: How to sync up the expiration time of Next Auth Session and a token coming from the server as I chose Credentials in provider of next-Auth
body: <p>I have implemented a next-auth authentication system for my Next.js app. In the providers, I have chosen credentials because I have a node.js backend server.</p>
  <p>The problem that I am facing is the expiration of next auth session is not in sync up with the expiration of jwt token on my backend. This is leading to inconsistency. Kindly help me out.</p>
  <p>Below is my next auth code</p>
  <pre><code>import NextAuth, {
    NextAuthOptions,
    Session,
    SessionStrategy,
    User,
  } from &quot;next-auth&quot;;
  import CredentialsProvider from &quot;next-auth/providers/credentials&quot;;
  import { login } from &quot;@actions/auth&quot;;
  import { toast } from &quot;react-toastify&quot;;
  import { JWT } from &quot;next-auth/jwt&quot;;
  import { NextApiRequest, NextApiResponse } from &quot;next&quot;;
  import { SessionToken } from &quot;next-auth/core/lib/cookie&quot;;
  
  // For more information on each option (and a full list of options) go to
  // https://next-auth.js.org/configuration/options
  const nextAuthOptions = (req: NextApiRequest, res: NextApiResponse) =&gt; {
    return {
      providers: [
        CredentialsProvider({
          name: &quot;Credentials&quot;,
          credentials: {
            email: { label: &quot;Email&quot;, type: &quot;text&quot; },
            password: { label: &quot;Password&quot;, type: &quot;password&quot; },
          },
          async authorize(
            credentials: Record&lt;&quot;email&quot; | &quot;password&quot;, string&gt; | undefined,
            req
          ): Promise&lt;Omit&lt;User, &quot;id&quot;&gt; | { id?: string | undefined } | null&gt; {
            // Add logic here to look up the user from the credentials supplied
            const response = await login(
              credentials?.email!,
              credentials?.password!
            );
            const cookies = response.headers[&quot;set-cookie&quot;];
  
            res.setHeader(&quot;Set-Cookie&quot;, cookies);
            if (response) {
              var user = { token: response.data.token, data: response.data.user };
              return user;
            } else {
              return null;
            }
          },
        }),
      ],
      refetchInterval: 1 * 24 * 60 * 60,
      secret: process.env.NEXTAUTH_SECRET,
      debug: true,
      session: {
        strategy: &quot;jwt&quot; as SessionStrategy,
        maxAge: 3 * 24 * 60 * 60,
      },
      jwt: {
        maxAge: 3 * 24 * 60 * 60,
      },
      callbacks: {
        jwt: async ({ token, user }: { token: JWT; user?: User }) =&gt; {
          user &amp;&amp; (token.accessToken = user.token);
          user &amp;&amp; (token.user = user.data);
          return token;
        },
        session: async ({ session, token }: { session: Session; token: JWT }) =&gt; {
          session.user = token.user;
          session.accessToken = token.accessToken;
          return session;
        },
      },
    };
  };
  export default (req: NextApiRequest, res: NextApiResponse) =&gt; {
    return NextAuth(req, res, nextAuthOptions(req, res));
  };
  </code></pre>