I have been reading the user documentation for browser login Persistence at Google Documentation . However its not clear enough, on what I should be doing for v9. Briefly here's what I understood. There are three types of persistence's: Per Session, Per Browser, and None. So now what I wanted to do was set Persistence for "per Browser". I saw two functions being used, one is inMemoryPersistence
which I assumed to be per Browser and the other to be browserSessionPersistence
which i assumed to be "per Session". However even after trying with both of them, after closing the tab and reopening its sends me to the login page.
const auth = getAuth(); setPersistence(auth, browserSessionPersistence).then(() => { // Existing and future Auth states are now persisted in the current // session only. Closing the window would clear any existing state even // if a user forgets to sign out. //... // New sign-in will be persisted with session persistence. return signInWithEmailAndPassword(auth, email, password); }).catch((error) => { // Handle Errors here. const errorCode = error.code; const errorMessage = error.message; });
browserSessionPersistance
being one of two parameters I tried.
So my question is:
(Also I'm using Vanilla Javascript with Modular Import)
If you want to persist auth state and required explicit logout, use browserLocalPersistence
.
Version V8 firebase.auth.Auth |
Version V9 | Description |
---|---|---|
Persistence.LOCAL |
browserLocalPersistence |
Explit logout required |
Persistence.SESSION |
browserSessionPersistence |
current session or tab, cleared when closed |
Persistence.NONE |
inMemoryPersistence |
in memory , not persisted, cleared when page is refreshed |
Also checkout Persistence interface in the documentation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.