title: Error when encoding and decoding jwt on next-auth
body: <p>On next-auth when just using the callbacks object <a href="https://next-auth.js.org/configuration/callbacks" rel="nofollow noreferrer">https://next-auth.js.org/configuration/callbacks</a> everything works fine, I can log in with google. and a jwt gets correctly generated.</p>
  <pre><code>  callbacks: {
      async jwt({ token }) {
        console.log(&quot;token callback jwt: &quot;, token)
        token.userRole = &quot;admin&quot;
        return token
      },
      async session(session) {
        console.log(&quot;session callback: &quot;, session)
        const encodedToken = await jwt.sign(session.session.user, jwtSecret.key, {
          algorithm: jwtSecret.type,
        })
  
        session.token = encodedToken
        return session
      },
    },
  </code></pre>
  <p>But my end goal is to use next-auth jwt with hasura and for that I need to encode some more information to my jwt</p>
  <p>I encode that information inside the jwt object <a href="https://next-auth.js.org/configuration/options#jwt" rel="nofollow noreferrer">https://next-auth.js.org/configuration/options#jwt</a></p>
  <p>this is my jwt object with encode and decode logic</p>
  <pre><code>  jwt: {
      encode: async ({ token }) =&gt; {
        const tokenContents = {
          id: token.id,
          name: token.name,
          email: token.email,
          picture: token.picture,
          &quot;https://hasura.io/jwt/claims&quot;: {
            &quot;x-hasura-allowed-roles&quot;: [&quot;admin&quot;, &quot;user&quot;],
            &quot;x-hasura-default-role&quot;: &quot;user&quot;,
            &quot;x-hasura-role&quot;: &quot;user&quot;,
            &quot;x-hasura-user-id&quot;: token.id,
          },
          iat: Date.now() / 1000,
          exp: Math.floor(Date.now() / 1000) + 24 * 60 * 60,
          sub: token.id,
        }
        const encodedToken = jwt.sign(tokenContents, jwtSecret.key, {
          algorithm: jwtSecret.type,
        })
        return encodedToken
      },
      decode: async ({ token }) =&gt; {
        const decodedToken = jwt.verify(token, jwtSecret.key, {
          algorithms: jwtSecret.type,
        })
        console.log(&quot;decodedToken: &quot;, decodedToken)
        return decodedToken
      },
    },
  </code></pre>
  <p>when I try to log in with my new encode decode logic, I receive next error that comes from node_modules &gt; openid-client &gt; lib &gt; client.js</p>
  <pre><code>https://next-auth.js.org/errors#oauth_callback_error checks.state argument is missing {
    error: {
      message: 'checks.state argument is missing',
      stack: 'TypeError: checks.state argument is missing\n' +
        '    at Client.callback (/var/task/node_modules/openid-client/lib/client.js:385:13)\n' +
        '    at oAuthCallback (/var/task/node_modules/next-auth/core/lib/oauth/callback.js:112:29)\n' +
        '    at processTicksAndRejections (internal/process/task_queues.js:95:5)\n' +
        '    at async Object.callback (/var/task/node_modules/next-auth/core/routes/callback.js:50:11)\n' +
        '    at async NextAuthHandler (/var/task/node_modules/next-auth/core/index.js:139:28)\n' +
        '    at async NextAuthNextHandler (/var/task/node_modules/next-auth/next/index.js:21:19)\n' +
        '    at async /var/task/node_modules/next-auth/next/index.js:57:32\n' +
        '    at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils/node.js:182:9)\n' +
        '    at async NextNodeServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:386:9)\n' +
        '    at async Object.fn (/var/task/node_modules/next/dist/server/base-server.js:488:37)',
      name: 'TypeError'
    },
    providerId: 'google',
    message: 'checks.state argument is missing'
  }
  </code></pre>
  <p>Just for curiosity I went to the client.js file where the code is breaking and this is the code inside, it has a if !checks.state throw new TypeError</p>
  <pre><code>if (params.state &amp;&amp; !checks.state) {
    throw new TypeError('checks.state argument is missing');
  }
  </code></pre>
  <p>It looks almost obvious that I need to add that checks.state to my encode logic but I don't know how, also I don't know that that checks.state object represents</p>