-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Hub TypeError: Cannot read property 'setItem' of undefined (AuthClass) #3278
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems. |
this is an actual issue, can we reopen it |
facing the same using AuthClass directly: const { AuthClass } = require('@aws-amplify/auth');
const auth = new AuthClass({
"identityPoolId": 'some-IdentityPoolId',
"userPoolId": 'som-userPoolId',
"userPoolWebClientId": 'some-userPoolWebClientId',
region: 'some-region',
});
(async () => {
try {
const res = await auth.signIn('abc@one.com', '123456')
console.log('===res', res)
} catch (e) {
console.log('===e', e)
}
})() |
@sammartinez multiple users have requested this issue be re-opened. |
Apologizes that this got closed, @mtraynham Can you explain your use case a little bit more? Im curious on why you are using AuthClass instead of just |
@sammartinez It's been a while, so I believe this is because to configure that particular global constant instance, the documentation suggests you pull in all of import Amplify, { Auth } from '@aws-amplify';
import awsconfig from './aws-exports';
Amplify.configure(awsconfig); https://aws-amplify.github.io/docs/js/authentication#manual-setup In reality, I only want a subset of the amplify functionality which is authentication. Although I just realized, I guess you could likely pull in import Auth from '@aws-amplify/auth';
Auth.configure({...}); It's honestly been a while since I've touched the code (Sept 2018), so I can't exactly remember what I did while getting this all setup. Pertaining to the bug, I could see multiple instances of AuthClass being used in a single app (even though I'm not doing it), but the scope of that question may be beyond this bug. Feel free to advise us (or me) if we should take a different route here, such as configuring the global constant instead of a second instance. Edit I tried out your suggestion. Everything seems to work the same, and the console error is gone. Seems like the vendor file is roughly the same size as well, so I'm guessing it didn't pull anything extra in. |
@harmohan-a @sepo-one issue re-opened fyi. |
My use case is that i don't want any global configuration. |
Similar to @mtraynham, we only use Amplify's auth module and hit this bug with the following: import { AuthClass } from '@aws-amplify/auth';
const auth = new AuthClass({
region: 'eu-west-2',
userPoolId: 'my-pool-id',
userPoolWebClientId: 'my-client-id',
}); |
Problem actually lies in here: https://github.com/aws-amplify/amplify-js/blob/master/packages/auth/src/index.ts. An instance is created with null config. (might come up with pull request if have some time). |
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 this would throw error in console because api internally uses auth as well and initiate a new instance of auth with null config.... 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! |
Im going to move this under a feature request, from what I am reading it seems that people are looking to utilizing |
I'm using |
Yeah, if you start to modularise the API and the other parts of Amplify, why not AUTH. |
This issue has been around for a while & may be addressed in a few different ways:
With these changes & more in the past year-and-a-half, this issue should be resolved. If not, please open a new issue with specifics so we can address it based on our new SSR & modularization support 🙏 |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Describe the bug
It seems
import {AuthClass} from '@aws-amplify/auth';
is defining an instance ofAuthClass
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 benull
throwing a null pointer exception which can lead to console errors like: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:
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):
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.
The text was updated successfully, but these errors were encountered: