Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase auth with LOCAL persistence not working from a Worker context #2903

Closed
raphaelbs opened this issue Apr 14, 2020 · 4 comments · Fixed by #2907
Closed

Firebase auth with LOCAL persistence not working from a Worker context #2903

raphaelbs opened this issue Apr 14, 2020 · 4 comments · Fixed by #2907

Comments

@raphaelbs
Copy link

[REQUIRED] Describe your environment

  • Operating System version: Ubuntu 19.04
  • Browser version: Chrome Version 81.0.4044.92 (Official Build) (64-bit)
  • Firebase SDK version: 7.12.0
  • Firebase Product: auth

[REQUIRED] Describe the problem

Steps to reproduce:

While using firebase auth within a web worker, with persistence set to firebase.auth.Auth.Persistence.LOCAL, console is logging the UNSUPPORTED_PERSISTENCE error: The current environment does not support the specified persistence type.

Relevant Code:

Debugging the firebase code, the problem seems to be caused by isWebStorageSupported method, because it checks for localStorage before running the try/catch block but, as the Worker doesn't have localStorage, it goes directly into the return statement:

image

// worker.js

const auth = firebase.app().auth();
auth.setPersistence(firebase.auth.Auth.Persistence.LOCAL)
        .then(() => auth.signInWithCustomToken(token));
@raphaelbs
Copy link
Author

@thebrianchen the auth should work or it also depends on localStorage?

@bojeil-google
Copy link
Contributor

Local persistence is the default for a worker environment. In a worker environment, indexedDB is used. You don't even need to specify it. Can you try again without specifying it? If that works, we can fix this so it works when it is explicitly specified in that environment.

@raphaelbs
Copy link
Author

raphaelbs commented Apr 14, 2020

It worked indeed! Thank you so much for the quick response @bojeil-google!

It would be great if this information was linked somewhere in the docs e.g.
https://firebase.google.com/docs/auth/web/auth-state-persistence

@bojeil-google
Copy link
Contributor

Let's keep this open. I will send a quick fix to fix this.

@bojeil-google bojeil-google reopened this Apr 14, 2020
@firebase firebase locked and limited conversation to collaborators May 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants