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.

Hub TypeError: Cannot read property 'setItem' of undefined (AuthClass)

See original GitHub issue

Describe the bug It seems import {AuthClass} from '@aws-amplify/auth'; is defining an instance of AuthClass without any configuration (new AuthClass(null)) as the default instance via these lines https://github.com/aws-amplify/amplify-js/blob/master/packages/auth/src/index.ts#L24.

The AuthClass listens to Hub via these lines, https://github.com/aws-amplify/amplify-js/blob/master/packages/auth/src/Auth.ts#L111-L125 and the storage here would be null throwing a null pointer exception which can lead to console errors like:

[ERROR] 27:39.356 Hub TypeError: Cannot read property 'setItem' of undefined
    at Object.callback (Auth.js:95)
    at Hub.js:122
    at Array.forEach (<anonymous>)
    at HubClass.push../node_modules/@aws-amplify/core/lib/Hub.js.HubClass._toListeners (Hub.js:119)
    at HubClass.push../node_modules/@aws-amplify/core/lib/Hub.js.HubClass.dispatch (Hub.js:77)
    at dispatchAuthEvent (Auth.js:61)
    at AuthClass.<anonymous> (Auth.js:387)
    at step (Auth.js:44)
    at Object.next (Auth.js:25)
    at fulfilled (Auth.js:16)

In my case, I define my own instance of the AuthClass with the proper configuration options, so really this Hub listener is called twice for both instances. My instance that I defined with all the proper configuration seems to have storage correctly configured there and does not throw the error.

To Reproduce Steps to reproduce the behavior:

  1. Use a second AuthClass instance for managing your user pool.

Expected behavior It does not create a default instance? Or maybe it handles the null pointer without exception?

Screenshots

Desktop (please complete the following information):

  • OS: Mac OS
  • Browser Chrome
  • Version 74

Additional context

Sample code

You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = ‘DEBUG’; in your app.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
harmohan-acommented, Oct 25, 2019

Soooo…this is the problem i had, and i’ll try to phrase it in a nicer way than i did to mean at the time.

i was using the api and the auth. from their modules

import API, { graphqlOperation } from ‘@aws-amplify/API’;

API.configure(…)

and import Auth from ‘@aws-amplify/Auth’; API.configure(…)

this would throw error in console because api internally uses auth as well and initiate a new instance of auth with null config… problem, but not a huge problem … everything still works

But, when you have API using cognito userpool as authentication it wouldnt work because again API creates its own instance of Auth with null configuration.

the alternative is to use the whole of amplify, which is not tree shakable, it builds with everything…everything, my build size increases by 5mb!

1reaction
mattiLeBlanccommented, Apr 20, 2020

Yeah, if you start to modularise the API and the other parts of Amplify, why not AUTH. We only use AUTH and API. I don’t want the rest polluting my bundle. It is already over 5 mb because of aws-amplify. When can we expect @amplify/auth to be released? It is still sitting at version 1.6.3?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read properties of undefined ...
You have put "window" with a capital w . You can use the following: Using lowercase window. const lightThemeCheckbox = document.
Read more >
AuthClass | amplify-js
This was previously used by an authenticated user to get MFAOptions, but no longer returns a meaningful response. Refer to the documentation for...
Read more >
aws-amplify-auth.min.js.map - UNPKG
toLowerCase()\n loweredCase = true\n }\n }\n}\n\n// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect\n// Buffer instances ...
Read more >
TypeError: Cannot read property 'computeModPow' of undefined
AWS Amplify + React Native - TypeError: Cannot read property 'computeModPow' of undefined. Recently, I've started learning React Native with ...
Read more >
Cannot read properties of undefined' - JavaScript Debugging
How To Fix 'Uncaught TypeError : Cannot read properties of undefined ' - JavaScript Debugging.
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