WARNING onHubCapsule is Deprecated (React)
See original GitHub issueI was using the Hub
API with my React app to handle authentication. I just upgraded to the latest aws-amplify
version and am now getting a warning in the console:
[WARN] 38:57.297 Hub - WARNING onHubCapsule is Deprecated. Please pass in a callback.
Note the three numbers at the beginning (i.e. 38:57:297) seem to be random. Every time I reload they are different. I don’t know what the message means by ‘pass in a callback’. Pass into where? And what should be in the callback?
Here’s my code:
const App = () => {
const [user, setUser] = useState(null)
const getUserData = async () => {
const currentUser = await Auth.currentAuthenticatedUser()
setUser(currentUser)
}
const hubObj = {
onHubCapsule: capsule => {
switch (capsule.payload.event) {
case 'signIn':
getUserData()
break
case 'signOut':
setUser(null)
break
default:
return
}
},
}
useEffectAsync(() => {
getUserData()
Hub.listen('auth', hubObj, 'onHubCapsule')
}, [])
const handleSignOut = async () => {
try {
await Auth.signOut({ global: true })
} catch (err) {
console.error('Error signing out user', err)
}
}
return user ? (
<AuthContext.Provider
value={{ username: user.username, handleSignOut, user }}>
<Router user={user} />
</AuthContext.Provider>
) : (
<Authenticator theme={theme} />
)
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Utilities - Hub - JavaScript - AWS Amplify Docs
While still possible, this is no longer considered best practice and we have begun deprecating the method. Please define an explicit callback and...
Read more >Authenticator | amplify-js
Defined in packages/aws-amplify-react-native/src/Auth/Authenticator.tsx:77 ... onHubCapsule(capsule: HubCapsule): any.
Read more >Warning message "DeprecationWarning: Invalid 'main' field in ...
This warning message will only show on Node 16. You can safely ignore the warning, but to get rid of it you can...
Read more >aws-amplify-react - UNPKG
This is deprecated ' +\n 'and will throw in the standalone `prop-types` package. ' +\n 'You may be seeing this warning due to...
Read more >Announcing AWS Amplify JavaScript library version 5
Deprecated legacy UI packages (You can migrate to the new UI ... Get started with building JavaScript Web and React Native apps with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi thanks @medelman17 for sharing your solution for my code instead of:
I changed my code to:
And now it’s working without the warning message.
Ok, but, for the record, it does not appear to be backwards compatible. Previously, I had this code which was working fine.
After the upgrade, I started to get
this.handleAuthFlow
is not a function errors. Changing to the new API solved it: