aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.41k stars 2.12k forks source link

Hub.listen no longer working #6947

Closed ShehryarKh closed 3 years ago

ShehryarKh commented 3 years ago

Describe the bug Hub listeners no longer behaving as expected. I try to console log and get nothing.

async beforeCreate() {
  Hub.listen("storage", (payload) => {
    console.log(payload["payload"]["event"] == "upload");
  }
}
ShehryarKh commented 3 years ago

Okay, I got the exact bug.

Inside my beforeCreate() There was an api call that was failing

    const user = await API.graphql({
      query: listUsers,
      authMode: "API_KEY",
      filter: {
        email: {
          eq: profileEmail,
        },
      },
    });

this call returned an unauthorized error. Somehow, once i fixed that, the events started to come through. Not sure if this is a bug or a feature.

sammartinez commented 3 years ago

@ShehryarKh This seems to be resolved with what you fixed. What is the beforeCreate() used for? Is this for Vue 3? The more detail you can provide us the better on reproducing this. Can you provide your package.json along with your environment settings?

Please use the follow command:

npx envinfo --system --binaries --browsers --npmPackages --npmGlobalPackages

Thanks ahead of time!

ShehryarKh commented 3 years ago

@sammartinez beforeCreate() was used for making some api calls, and also listening to storage events (Hub.listen("storage", (payload)). This is a vue2 project. package.json

{
System:
    OS: macOS 10.15.4
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    Memory: 74.78 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.8.0 - /usr/local/bin/node
    npm: 6.14.7 - /usr/local/bin/npm
  Browsers:
    Chrome: 86.0.4240.75
    Firefox: 81.0.1
    Safari: 13.1
  npmPackages:
    @aws-amplify/ui-vue: ^0.2.18 => 0.2.22
    @tailwindcss/custom-forms: ^0.2.1 => 0.2.1
    @vue/cli-plugin-babel: ~4.5.6 => 4.5.7
    @vue/cli-plugin-eslint: ~4.5.7 => 4.5.7
    @vue/cli-plugin-router: ^4.5.7 => 4.5.7
    @vue/cli-service: ~4.5.7 => 4.5.7
    ag-grid-vue: ^24.0.0 => 24.0.0
    apexcharts: ^3.20.1 => 3.22.0
    aws-amplify: ^3.2.0 => 3.3.3
    aws-amplify-vue: ^2.1.2 => 2.1.2
    aws-sdk: ^2.771.0 => 2.771.0
    axios: ^0.20.0 => 0.20.0
    axios-mock-adapter: ^1.18.2 => 1.18.2
    babel-eslint: ^10.1.0 => 10.1.0
    eslint: ^6.7.2 => 6.8.0
    eslint-plugin-vue: ^6.2.2 => 6.2.2
    file-loader: ^6.1.1 => 6.1.1
    material-icons: ^0.3.1 => 0.3.1
    moment: ^2.29.1 => 2.29.1
    node-sass: ^4.14.1 => 4.14.1
    postcss-loader: ^3.0.0 => 3.0.0
    sass: ^1.27.0 => 1.27.0
    sass-loader: ^10.0.3 => 10.0.3
    script-loader: ^0.7.2 => 0.7.2
    stylus-loader: ^3.0.2 => 3.0.2
    tailwindcss: ^1.8.12 => 1.8.13
    url-loader: ^4.1.0 => 4.1.1
    v-calendar: ^1.0.8 => 1.0.8
    v-tooltip: ^2.0.3 => 2.0.3
    vee-validate: ^3.4.0 => 3.4.0
    vue: ^2.6.12 => 2.6.12
    vue-apexcharts: ^1.6.0 => 1.6.0
    vue-backtotop: ^1.6.1 => 1.6.1
    vue-cli-plugin-vuetify: ~2.0.7 => 2.0.7
    vue-feather-icons: ^5.1.0 => 5.1.0
    vue-form-wizard: ^0.8.4 => 0.8.4
    vue-parallaxy: ^1.1.1 => 1.1.1
    vue-perfect-scrollbar: ^0.2.1 => 0.2.1
    vue-router: ^3.4.6 => 3.4.6
    vue-select: ^3.10.8 => 3.10.8
    vue-template-compiler: ^2.6.12 => 2.6.12
    vue-tour: ^1.5.0 => 1.5.0
    vue2-hammer: ^2.1.2 => 2.1.2
    vuesax: ^3.11.17 => 3.12.2
    vuex: ^3.5.1 => 3.5.1
    vuex-persist: ^3.1.3 => 3.1.3
  npmGlobalPackages:
    @aws-amplify/cli: 4.29.6
    @vue/cli-service-global: 4.1.2
    @vue/cli: 4.5.7
    expo-cli: 3.11.5
    github-release-notes: 0.17.1
    node-sass: 4.14.0
    npm-check-updates: 7.0.1
    npm: 6.14.7
    react-scripts: 3.4.1
    serve: 11.3.0
}
wei commented 3 years ago

@ShehryarKh In order to receive Hub events on storage channel, please make sure track: true is in the config passed into Storage.put, or any other Storage.[method].

Please let us know if adding track: true was part of the fix that resolved the issue.

ShehryarKh commented 3 years ago

@wei Its a little difficult to reproduce. I will try to run into the same error.

wei commented 3 years ago

@ShehryarKh Thanks so much! If you could provide a minimal reproducible repo I'd be more than glad to take a look. But I highly suspect the track: true was left out. : D

github-actions[bot] commented 2 years ago

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 *-help channels or Discussions for those types of questions.