React Error: An AuthUI instance already exists for the key "[DEFAULT]"
See original GitHub issueApparently, 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.
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:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top 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 >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
You could also keep a static reference to the delete promise. something like:
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.