Skip to content

Uncaught auth error #43

@jacksteamdev

Description

@jacksteamdev

When I use useAuthState with signInWithPopup and close the popup without authenticating, the error state is not reached.

After a second these two errors appear in the console:

Uncaught: {code: "auth/popup-closed-by-user", message: "The popup has been closed by the user before finalizing the operation."}

Uncaught Error: The error you provided does not contain a stack trace.

I was expecting this error to cause useAuthState to reach the error state. Is this behavior expected?

The following code dropped into the CreateReactApp boilerplate will reproduce this error. In fact, all errors seem to cause the aforementioned result.

import React from 'react'

import * as firebase from 'firebase/app'
import 'firebase/auth'

import { useAuthState } from 'react-firebase-hooks/auth'

const firebaseConfig = {
  // copied from firebase console
}

firebase.initializeApp(firebaseConfig)

const provider = new firebase.auth.GoogleAuthProvider()

const login = () => {
  firebase.auth().signInWithPopup(provider)
}

export const logout = () => {
  firebase.auth().signOut()
}

export const App = () => {
  const [user, initialising, error] = useAuthState(
    firebase.auth(),
  )

  if (initialising) {
    return (
      <div>
        <p>Initialising User...</p>
      </div>
    )
  }
  if (error) {
    return (
      <div>
        <p>Error: {error}</p>
      </div>
    )
  }
  if (user) {
    return (
      <div>
        <p>Current User: {user.email}</p>
        <button onClick={logout}>Log out</button>
      </div>
    )
  }

  return <button onClick={login}>Log in</button>
}

My package versions:

{
  "firebase": "^6.6.2",
  "react": "^16.9.0",
  "react-firebase-hooks": "^2.1.0",
}

Thanks for the great library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions