angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Setting Persistence Doesn't Work

Open flauc opened this issue 2 years ago • 7 comments

Currently running setPersistence with any Persistence breaks. I was able to work around this by just importing setPersistence from @firebase/auth instead of @angular/fire/auth.

Version info

Angular: 13.1.3

Firebase: 9.6.4

AngularFire: 7.2.0

Other (e.g. Ionic/Cordova, Node, browser, operating system): Node 17.x; OS Windows 11; Browser Chrome;

How to reproduce these conditions

Try setting persistance:

setPersistence(this.auth, browserSessionPersistence).catch(console.error);

Debug output

TypeError: Class constructor BrowserSessionPersistence cannot be invoked without 'new'
    at angular-fire.js:206:29
    at angular-fire.js:163:45
    at ZoneDelegate.invoke (zone.js:372:1)
    at Object.onInvoke (core.mjs:25457:1)
    at ZoneDelegate.invoke (zone.js:371:1)
    at Zone.run (zone.js:134:1)
    at NgZone.run (core.mjs:25311:1)
    at run (angular-fire.js:163:35)
    at new <anonymous> (angular-fire.js:206:16)
    at _getInstance (index-bc414788.js:535:16)

Expected behavior

Setting persistence works.

Actual behavior

Setting persistence doesn't work.

flauc avatar Jan 25 '22 06:01 flauc

This is related with issue #3038

vandres avatar Jan 26 '22 13:01 vandres

I was able to workaround this with import { setPersistence } from '@firebase/auth' only, browserSessionPersistence can be imported from @angular/fire/auth.

Idomo avatar Feb 27 '22 19:02 Idomo

Check this pull request it has new docs in that I have added how to use persistence correctly #3174

Sapython avatar Mar 10 '22 18:03 Sapython

Settings persistence in this way is correct, the issue is that it does not work if the function is imported from @angular/fire/auth.

@jamesdaniels any ideas?

romanhuba avatar Sep 27 '22 12:09 romanhuba

Anyone has managed to solve this issue? I'm facing it right now and it's so annoying

IvanColucciSW avatar Sep 01 '23 10:09 IvanColucciSW

this is the correct format this.auth.setPersistence(browserLocalPersistence).then(e=>{ ...... .... })

TechieWithBeard avatar Feb 08 '24 11:02 TechieWithBeard

this is the correct format this.auth.setPersistence(browserLocalPersistence).then(e=>{ ...... .... })

It worked for me, thanks

mcdalir avatar May 03 '24 01:05 mcdalir