挂钩错误:"错误:AuthUI实例已存在

时间:2017-12-01 08:18:10

标签: javascript firebase vue.js single-page-application socialauth

我使用 Vuejs 构建单页应用,并使用Firebase进行身份验证。到目前为止,我已登录并注册工作,没有任何问题。我现在遇到的问题是社交身份验证

当我加载注册页面时,社交按钮会呈现,但当我离开并返回注册时,我收到以下错误:

挂钩时出错:"错误:已存在AuthUI实例

并且社交按钮不再渲染。

这是我的代码:

mounted () {
  SocialAuth () {
    const uiConfig = {
      signInSuccessUrl: '/',
      signInOptions: [
        firebase.auth.GoogleAuthProvider.PROVIDER_ID,
        firebase.auth.FacebookAuthProvider.PROVIDER_ID,
        firebase.auth.TwitterAuthProvider.PROVIDER_ID
      ]
    }

    const ui = new firebaseui.auth.AuthUI(firebase.auth())
    ui.start('#firebaseui-auth-container', uiConfig)
  }
}

非常感谢任何帮助和所有帮助:)

1 个答案:

答案 0 :(得分:8)

您是否尝试过使用firebaseui.auth.AuthUI.getInstance()

mounted () {
  SocialAuth () {
    const uiConfig = {
      signInSuccessUrl: '/',
      signInOptions: [
        firebase.auth.GoogleAuthProvider.PROVIDER_ID,
        firebase.auth.FacebookAuthProvider.PROVIDER_ID,
        firebase.auth.TwitterAuthProvider.PROVIDER_ID
      ]
    }

    if(firebaseui.auth.AuthUI.getInstance()) {
      const ui = firebaseui.auth.AuthUI.getInstance()
      ui.start('#firebaseui-auth-container', uiConfig)
    } else {
      const ui = new firebaseui.auth.AuthUI(firebase.auth())
      ui.start('#firebaseui-auth-container', uiConfig)
    }
  }
}