1

我已经成功地将 AWS Amplify 的 Auth UI 功能和组件与 Gridsome 集成以实现简单的登录/注销功能,但是当我尝试使用 Amplify Event Bus 访问

import { AmplifyEventBus } from "aws-amplify-vue"

我得到错误:

Error in mounted hook (Promise/async): "TypeError: Cannot read property 'Logger' of undefined"

在 github 帖子上发现了一个类似的问题并添加了建议的

Vue.prototype.$Amplify = Amplify;

确实删除了警告,但 Auth UI Logout 组件将不再显示。我可以登录,但没有显示注销按钮。我不明白为什么当 UI 组件已经在没有它的情况下工作时,访问事件总线需要我将 Amplify 添加到 Vue 原型中,以及为什么即使我添加了它,组件仍然没有出现。

4

1 回答 1

2

AmplifyEventBus已经停产,所以现在考虑Legacy

相反,使用Hub.listen,如下所示:

<script>
import { Hub } from 'aws-amplify'

export default {
  mounted() {
    Hub.listen('auth', (info) => {
      console.log('auth event:', info)
    })
  },
}
</script>

Logger 也可以用同样的方式导入,比如:

import { Hub, Logger } from 'aws-amplify'
于 2020-06-25T14:12:54.527 回答