Closed devinshoemaker closed 1 year ago
You can change the persistence type to none
on the Auth instance being passed to FirebaseUI: https://firebase.google.com/docs/auth/web/auth-state-persistence
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.NONE).then(() => {
ui = new firebaseui.auth.AuthUI(firebase.auth());
});
@wti806 I'm getting the same error using your approach. Any other ideas?
You can change the persistence type to
none
on the Auth instance being passed to FirebaseUI: https://firebase.google.com/docs/auth/web/auth-state-persistencefirebase.auth().setPersistence(firebase.auth.Auth.Persistence.NONE).then(() => { ui = new firebaseui.auth.AuthUI(firebase.auth()); });
Yes this does not work
It did not work for me either. This is the auth I am passing in:
firebase.auth.Auth.Persistence.NONE;
const firebaseApp: firebase.app.App = firebase.initializeApp(firebaseConfig);
export const auth = firebaseApp.auth();
@wti806 are there any other possible workarounds for this?
@wti806 are there any other possible workarounds for this?
I ended up using plain JS and buidling my own ui.
Has anyone found a solution or a possible workaround for this?
My solution was to set persistence and then start the ui. Persistence will check if env is testing and set it to none otherwise it can default to local or session if there's a remember me option.
Here is a snippet
firebase
.auth()
// can set session if remember me option exists
.setPersistence(process.env.NODE_ENV === 'test' ? firebase.auth.Auth.Persistence.NONE : firebase.auth.Auth.Persistence.LOCAL)
.then(function () {
// get the firebaseui instance
const ui =
firebaseui.auth.AuthUI.getInstance() ||
new firebaseui.auth.AuthUI(firebase.auth())
ui.start('#firebaseui-auth-container', {/*firebase config here*/})
})
My solution was to set persistence and then start the ui. Persistence will check if env is testing and set it to none otherwise it can default to local or session if there's a remember me option.
Here is a snippet
firebase .auth() // can set session if remember me option exists .setPersistence(process.env.NODE_ENV === 'test' ? firebase.auth.Auth.Persistence.NONE : firebase.auth.Auth.Persistence.LOCAL) .then(function () { // get the firebaseui instance const ui = firebaseui.auth.AuthUI.getInstance() || new firebaseui.auth.AuthUI(firebase.auth()) ui.start('#firebaseui-auth-container', {/*firebase config here*/}) })
This worked for me. thank you.
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
When using Jest to write a test on a component that uses Firebase UI, the test fails due to the error "The current environment does not support the specified persistence type." This is due to the fact that this library always sets the persistence type to
SESSION
regardless of the Node environment. However, thetest
Node environment does not support this type of persistence, and consequently, the persistence should be set toNONE
in this case. There does not seem to be a way of overriding this, and potentially no way of writing Jest unit tests for a component that utilizes this library. I believe that this could be handled by simply checking theprocess.env.NODE_ENV
and setting the persistence toNONE
if the environment istest
, or the library could allow us to pass this in as an optional property.If I get some time then I may experiment with a couple of approaches, but if a maintainer has an opinion on how to go about this then I am open to suggestions.
Error: