`account.access_token` & `account.refresh_token` 在使用带有 `next-auth` 的 Twitter Provider 时是 `undefined`?

`account.access_token` & `account.refresh_token` is `undefined` when using Twitter Provider with `next-auth`?

我正在关注 this tutorial & am unable to get the value of access_token & refresh_token from next-auth。我的回调函数如下所示:

callbacks: {
    async jwt({ token, account, user }) {
      if (account) {
        token[account.provider] = {
          accessToken: account.access_token,
          refreshToken: account.refresh_token,
        }
        console.log(token[account.provider])
      }

      return token
    },
  },

它目前将 { accessToken: undefined, refreshToken: undefined } 记录到控制台。

这是它的显示方式in the docs when using jwt callbacks,但它对我不起作用。

我已经在分支next-auth-with-twitter-api-v2https://github.com/deadcoder0904/twitter-api-v2-3-legged-login-using-next-connect/tree/next-auth-with-twitter-api-v2

上完成了复制

编辑:

看起来它适用于 v3。参见分支 next-auth-v3-with-twitter-api-v2https://github.com/deadcoder0904/twitter-api-v2-3-legged-login-using-next-connect/tree/next-auth-v3-with-twitter-api-v2

所以 access_token 重命名为 oauth_token & refresh_token 重命名为 oauth_token_secret:

callbacks: {
    async jwt({ token, account, user }) {
      if (account) {
        token[account.provider] = {
          accessToken: account.oauth_token,
          refreshToken: account.oauth_token_secret,
        }
      }

      return token
    },
  },