Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

twitter oauth2.0 callback error #12398

Open
mackieq opened this issue Dec 18, 2024 · 1 comment
Open

twitter oauth2.0 callback error #12398

mackieq opened this issue Dec 18, 2024 · 1 comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@mackieq
Copy link

mackieq commented Dec 18, 2024

Environment

  System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 5.62 GB / 15.34 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 20.18.0 - ~/.nvm/versions/node/v20.18.0/bin/node
    npm: 9.9.4 - ~/cgent/front-end/next-auth-example/node_modules/.bin/npm
    pnpm: 9.14.4 - ~/.nvm/versions/node/v20.18.0/bin/pnpm
  Browsers:
    Chrome: 131.0.6778.139
  npmPackages:
    next: 15.0.3 => 15.0.3 
    next-auth: ^4.24.11 => 4.24.11 
    react: ^18.2.0 => 18.3.1 

Reproduction URL

https://github.com/mackieq/next-auth-example

Describe the issue

Twitter login:

  1. Step 1: Construct an Authorize URL. (correct)
  2. Step 2: GET oauth2/authorize (correct)

after step 2, twitter redirect to http://localhost:3000/api/auth/callback/twitter?state=xxx&code=xxx

My nextjs console output error:


[next-auth][error][OAUTH_CALLBACK_ERROR] 
https://next-auth.js.org/errors#oauth_callback_error this.getName is not a function {
  error: Error [OAuthCallbackError]: this.getName is not a function
      at async AppRouteRouteModule.do (webpack://next/dist/src/server/route-modules/app-route/module.ts:529:14)
      at async AppRouteRouteModule.handle (webpack://next/dist/src/server/route-modules/app-route/module.ts:658:30)
      at async doRender (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/base-server.ts:2504:29)
      at async responseGenerator (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/base-server.ts:3027:21)
      at async DevServer.renderToResponseWithComponentsImpl (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/base-server.ts:3039:23)
      at async DevServer.renderPageComponent (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/base-server.ts:3597:15)
      at async DevServer.renderToResponseImpl (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/base-server.ts:3659:23)
      at async DevServer.pipeImpl (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/base-server.ts:1698:20)
      at async NextNodeServer.handleCatchallRenderRequest (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/next-server.ts:1034:6)
      at async DevServer.handleRequestImpl (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/base-server.ts:1462:8)
      at async (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/dev/next-dev-server.ts:514:13)
      at async Span.traceAsyncFn (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/trace/trace.ts:143:13)
      at async DevServer.handleRequest (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/dev/next-dev-server.ts:512:19)
      at async invokeRender (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/lib/router-server.ts:284:10)
      at async handleRequest (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/lib/router-server.ts:530:15)
      at async requestHandlerImpl (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/lib/router-server.ts:576:6)
      at async Server.requestListener (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/lib/start-server.ts:146:6)
    527 |         }
    528 |       } else {
  > 529 |         res = await workUnitAsyncStorage.run(
        |              ^
    530 |           requestStore,
    531 |           handler,
    532 |           request, {
    code: undefined
  },
  providerId: 'twitter',
  message: 'this.getName is not a function'
}

It seems like a certain field is missing or has an issue when fetching the user information.

How to reproduce

down load https://github.com/mackieq/next-auth-example, config twitter clientId and secret, then:

npm install
npm run dev

Expected behavior

login callback success

@mackieq mackieq added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Dec 18, 2024
@mackieq mackieq changed the title twitter callback api error twitter callback error Dec 18, 2024
@mackieq mackieq changed the title twitter callback error twitter oauth2.0 callback error Dec 27, 2024
@manmohan659
Copy link

The original error this.getName is not a function has been resolved with the proper Twitter provider configuration.

Looking at the logs, I can confirm that the Twitter OAuth flow is working correctly and successfully fetching all user data. The logs show:

  1. Successful OAuth initiation

  2. Complete profile data retrieval

  3. Proper token generation and management

  4. Working OAuth callback

Here's, something: it's redirecting to sign-in page. The remaining issue is purely a redirect problem after successful authentication. The logs show:

GET /api/auth/callback/twitter?state=[state]&code=[code] 302 GET /login 200

This redirect loop occurs because the app is missing proper session handling. The repository appears to be missing some essential files for NextAuth to work correctly:

  • SessionProvider wrapper in the root layout

  • Proper session/authentication state handling in components

  • NextAuth type definitions

Would you mind confirming if these files are part of the main repo but not included in the next-auth-example repo? If not, they should be added to ensure the complete authentication flow works correctly.

I can submit a PR with these additions if you'd like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

2 participants