question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot destructure property 'statusCode' of 'errors[error.toLowerCase(...)]' as it is undefined.

See original GitHub issue

I’m using next-auth 3.14.5

I’m currently working on a custom credentials provider, and when returning an error, the app fails and shows this error:

(node:72267) UnhandledPromiseRejectionWarning: TypeError: Cannot destructure property 'statusCode' of 'errors[error.toLowerCase(...)]' as it is undefined.
    at error (/Users/jahir/dev/jahir/synaptiko/fe/node_modules/next-auth/dist/server/pages/error.js:51:5)
    at Object.error (/Users/jahir/dev/jahir/synaptiko/fe/node_modules/next-auth/dist/server/pages/index.js:81:34)
    at /Users/jahir/dev/jahir/synaptiko/fe/node_modules/next-auth/dist/server/index.js:222:29
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/jahir/dev/jahir/synaptiko/fe/node_modules/next-auth/dist/server/index.js:52:103)
    at _next (/Users/jahir/dev/jahir/synaptiko/fe/node_modules/next-auth/dist/server/index.js:54:194)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:72267) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 132)
(node:72267) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This is my provider code:

const credentialsProvider: AuthProvider = Providers.Credentials({
  name: 'Synaptikö',
  credentials: {
    email: {
      label: 'Correo electrónico',
      type: 'email',
      placeholder: 'hola@email.com',
    },
    password: { label: 'Contraseña', type: 'password' },
  },
  async authorize(credentials): Promise<User | null> {
    try {
      const path = buildBackendUrl('/auth/login');
      const user = post(
        path,
        {
          email: credentials.email,
          password: credentials.password,
        },
        { headers: { accept: '*/*' } },
      )
        .then((user) => {
          console.log('user', user);
          const validUser: User = {};
          return null;
        })
        .catch((e) => {
          const errorMessage = e?.message ?? '';
          // This is where the error happens.
          throw new Error(
            `/?error=${encodeURI(errorMessage)}&email=${encodeURI(
              credentials.email || '',
            )}`,
          );
        });
      return user;
    } catch (e) {
      console.error('try', e);
      return null;
    }
  },
});

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
BillBuiltcommented, Apr 12, 2021

Accepted/understood error codes by the /error endpoint are: Default, Configuration, AccessDenied, Verification You probably don’t want to be more specific about the type of error for security reasons anyway. This is not documented anywhere as far as I can tell, could accept a PR, if you are interested.

Ok so I have this question then. Are the only acceptable parameters for the Error those four listed above? We can NOT send a custom error message like the example code states, rather only one of the four error codes?

From https://next-auth.js.org/providers/credentials // throw new Error('error message') // Redirect to error page

Instead it can only be one of these ? throw new Error( ["Default" | "Configuration" | "AccessDenied", "Verification"])

2reactions
balazsorban44commented, Apr 12, 2021

Accepted/understood error codes by the /error endpoint are: Default, Configuration, AccessDenied, Verification You probably don’t want to be more specific about the type of error for security reasons anyway. This is not documented anywhere as far as I can tell, could accept a PR, if you are interested.

If you want better UX for your user, check out the signIn client-side function’s {redirect: false option} https://next-auth.js.org/getting-started/client#using-the-redirect-false-option

We probably shouldn’t crash when a non-standard error is passed to /error though, so I created a fix at #1700

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'statusCode' of undefined
The response object might be undefined if no response was received so you have to check that it exists before accessing statusCode ....
Read more >
Cannot read property 'statusCode' of undefined in Synthetic ...
Bommisetty - The error message is stating that response is undefined, which is why it cannot read the statusCode property.
Read more >
HTTP/2 | Node.js v19.3.0 Documentation
destroyed property will be true and the http2stream.rstCode property will specify the RST_STREAM error code. The Http2Stream instance is no longer usable once ......
Read more >
ERROR TypeError: Cannot read property title of undefined
HEY, SET YOUR LIKE THERE !!! ------------------- ----- LIKE --- https://codedocu.com/Software/Angular/Angular- Error /Solv...
Read more >
HTTP2 - Node.js 中文文档
Note that this is not the same thing as an HTTP Response Status Code. Default: 0x00 (No Error). lastStreamID <number> The Stream ID...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found