question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Error: An AuthUI instance already exists for the key "[DEFAULT]"

See original GitHub issue

Apparently, the problem is due to the ui.delete() command being not fast enough. Notice below that the “delete” is resolved after a new instance’s constructor was fired already.

image

My code

import React from 'react'
import firebase from 'firebase'
import firebaseui from 'firebaseui'
import { Redirect } from 'react-router-dom';

import { auth } from '~/firebase'


export default class SignIn extends React.Component {
  state = {
    uiShown: false,
    redirect: false
  }

  ui // = new firebaseui.auth.AuthUI(auth)

  uiConfig = { ... }

  constructor(props) {
    super(props)
    console.debug('constructor')

    this.ui = new firebaseui.auth.AuthUI(auth)
  }

  componentDidMount() {
    this.ui.start('#firebaseui-auth-container', this.uiConfig)
  }

  componentWillUnmount() {
    console.debug('will unmount')
    this.ui.delete().then(() => console.debug('deleted'))
  }

  render() {
    return (
      <>
        <div id="firebaseui-auth-container"/>
        {!this.state.uiShown && <div id="loader">Loading...</div>}
        {this.state.redirect && <Redirect to="/dashboard"/>}
      </>
    )
  }
}

My app layout is such that I have some public and private pages. If private page is accessed when user is not logged in, he gets redirected to /signin page. The problem is when I am on /signin page and I access one of the other private pages - I am redirected back immediately and the tree containing the SignIn component gets re-mounted.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
nicolasgarniercommented, Mar 26, 2018

You could also keep a static reference to the delete promise. something like:

export default class SignIn extends React.Component {

  // ...

  // Resolved unless an instance of FirebaseUI is being deleted.
  static firebaseUiDeleted = Promise.resolve();

  componentDidMount() {
    SignIn.firebaseUiDeleted.then(() => {
      this.ui = new firebaseui.auth.AuthUI(auth)
      this.ui.start('#firebaseui-auth-container', this.uiConfig)
    })
  }

  componentWillUnmount() {
    SignIn.firebaseUiDeleted = this.ui.delete()
  }
}
1reaction
bojeil-googlecommented, Mar 26, 2018

Take a look at the code. It is open sourced: https://github.com/firebase/firebaseui-web/blob/master/javascript/widgets/authui.js#L812 We call signOut underneath on an internal Auth instance. The operation is asynchronous. Nothing we can do about it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: An AuthUI instance already exists for the key ... - GitHub
I am trying to get Firebase PhoneNumber Auth work in Cordova app based on MeteorJS. Meteor is a single-page app framework that dynamically ......
Read more >
Error in mounted hook: "Error: An AuthUI instance already exists
I building a single page app using Vuejs and using Firebase for authentication. So far I got sign in and sign up to...
Read more >
Error an Authui Instance Already Exist - Lua Software Code
Error: An AuthUI instance already exists for the key "[DEFAULT]". Solution. const ui = firebaseui.auth.AuthUI.
Read more >
Error: An AuthUI instance already exists-Vue.js - appsloveworld
Coding example for the question Error in mounted hook: "Error: An AuthUI instance already exists-Vue.js.
Read more >
Error: An AuthUI instance already exists for the key "[DEFAULT]"
Code. Language: JavaScript. // One-liner that solves this issue: var ui = firebaseui.auth.AuthUI.getInstance() || new firebaseui.auth.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found