Skip to content

The "key" argument must be of type string or an instance of ... or Buffer. Received undefined. #2170

@BenjaminWFox

Description

@BenjaminWFox

Description 🐜

On the next branch, I am testing #1591 - Both of the Azure providers seem to log in successfully on the provider side and when I am directed back to NextAuth I can see the callbacks signIn and jwt running with expected data about the signed in user.

However, after the jwt callback runs I receive the following error in the server console:

[next-auth][error][oauth_callback_handler_error]
https://next-auth.js.org/errors#oauth_callback_handler_error TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string or an instance of SecretKeyObject, ArrayBuffer, TypedArray, DataView, or Buffer. Received undefined
    at Object.hkdfSync (node:internal/crypto/hkdf:134:7)
    at hkdf (webpack-internal:///./next-auth/lib/jwt.js:151:70)
    at getDerivedSigningKey (webpack-internal:///./next-auth/lib/jwt.js:166:18)
    at Object.encode (webpack-internal:///./next-auth/lib/jwt.js:44:116)
    at Module.callback (webpack-internal:///./next-auth/server/routes/callback.js:123:43)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}

This may not be a bug, unsure where next branch is at. On the bright side, it doesn't seem like this is related to #1591 so I think that PR is working as expected.

How to reproduce ☕️

You should be able to reproduce by adding a basic AzureAD provider on the next branch and signing in. I'm not sure if this happens with other providers, as I don't have any available to test at the moment.

Screenshots / Logs 📽

This is everything I see happen from the time I click the "Sign In with Azure Active Directory" button, with logs added from the various callbacks:

event - build page: /api/auth/[...nextauth]
wait  - compiling...
event - compiled successfully
REDIRECT running...
REDIRECT running...
SIGNIN running...
JWT running...
[next-auth][warn][jwt_auto_generated_signing_key]
https://next-auth.js.org/warnings#jwt_auto_generated_signing_key
[next-auth][error][oauth_callback_handler_error]
https://next-auth.js.org/errors#oauth_callback_handler_error TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string or an instance of SecretKeyObject, ArrayBuffer, TypedArray, DataView, or Buffer. Received undefined
    at Object.hkdfSync (node:internal/crypto/hkdf:134:7)
    at hkdf (webpack-internal:///./next-auth/lib/jwt.js:151:70)
    at getDerivedSigningKey (webpack-internal:///./next-auth/lib/jwt.js:166:18)
    at Object.encode (webpack-internal:///./next-auth/lib/jwt.js:44:116)
    at Module.callback (webpack-internal:///./next-auth/server/routes/callback.js:123:43)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}
REDIRECT running...
REDIRECT running...

Environment 🖥

  System:
    OS: macOS 11.0.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 15.00 GB / 64.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.3.0 - ~/.nvm/versions/node/v16.3.0/bin/node
    Yarn: 1.22.0 - /usr/local/bin/yarn
    npm: 6.14.13 - ~/Documents/Projects/Code/External/next-auth/node_modules/.bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 91.0.4472.101
    Firefox: 86.0.1
    Safari: 14.0.1

Contributing 🙌🏽

It takes a lot of work 🏋🏻‍♀️ maintaining a library like next-auth; any contribution is more than welcome 💚

In case you're willing to help fix this bug, please let us know here, and we'll reach you 😊 . Otherwise, you can have a look at the issues labelled with "good first issue" and pick any of them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions