Skip to content

The current environment does not support the specified persistence type. (auth/unsupported-persistence-type) #976

Open
@sushantdhiman

Description

@sushantdhiman

Describe your environment

  • Operating System version: Arch Linux
  • Browser version: 103.0.2 (64-bit)
  • Firebase UI version: 6.x
  • Firebase SDK version: 9.10.0

Describe the problem

The following error is thrown when using Persistence.NONE and trying to create an auth instance on a browser which has its cookies disabled.

Uncaught (in promise) FirebaseError: Firebase: The current environment does not support the specified persistence type. (auth/unsupported-persistence-type).
    FirebaseError index.esm2017.js:791
    create index.esm2017.js:819
    createErrorInternal index-4dc22a28.js:474
    _assert index-4dc22a28.js:480
    _validatePersistenceArgument index.esm2017.js:201
    setPersistence index.esm2017.js:749
    Cn esm.js:347
    Login index.tsx:76

I believe the root cause behind this is the following code.

// Change persistence to session to avoid the risk of dangling auth states in
// local storage. Check if the current version used, supports it.
if (this.tempAuth_.setPersistence) {
this.tempAuth_.setPersistence(firebase.auth.Auth.Persistence.SESSION);
}

As you can see, this code tries to set Persistence.SESSION even when I have previously set Persistence.NONE in my firebase/auth instance.

Steps to reproduce:

  1. Set browser to reject cookies for your Firebase based application address, for example localhost:3001 in my case.
  2. Try to open page which is creating firebase instance, something like this (react code). Main idea is to set auth to Persistence.NONE and then try to create firebaseui auth instance.
  export default function Login() {
    const [ready, setReady] = useState(false);
    const elementRef = useRef<HTMLDivElement>(null);
  
    useEffect(() => {
      auth.setPersistence(firebase.auth.Auth.Persistence.NONE).then(() => {
        firebaseui.auth.AuthUI.prototype.
        setReady(true);
      });
    }, []);
  
    useEffect(() => {
      if (!ready) return;
  
      const widget =
        firebaseui.auth.AuthUI.getInstance() || new firebaseui.auth.AuthUI(auth);
  
      if (elementRef.current) {
        widget.start(elementRef.current, uiConfig);
      }
  
      return () => {
        widget.reset();
      };
    }, [ready, elementRef]);

   // code
   return (
      <div ref={elementRef} />
    );
}

How to fix:

I believe this.tempAuth_.setPersistence should be using persistence information from firebase.auth instance passed to it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions