I need to persist the user across sessions in node - is there to do this?
I found a few problems with this issue:
That is not currently available. We will consider it in our modularization efforts.
Can you suggest a workaround? Maybe use onIdTokenChanged to save the user and updateCurrentUser on startup to restore? Problem with that is deserializing the user with the correct prototype
Bit late to the party, but this workaround worked for me:
Save user:
const userJson = JSON.stringify(currentUser.toJSON())
// Write userJson to disk
Load user:
// Read userJson from disk
const userData = JSON.parse(userJson)
const user = new firebase.User(userData, userData.stsTokenManager, userData)
firebase.auth().updateCurrentUser(user)
Bit late to the party, but this workaround worked for me:
Save user:
const userJson = JSON.stringify(currentUser.toJSON()) // Write userJson to diskLoad user:
// Read userJson from disk const userData = JSON.parse(userJson) const user = new firebase.User(userData, userData.stsTokenManager, userData) firebase.auth().updateCurrentUser(user)
@JakeHedman I would love to implement this, but at least in my Typescript setup I get the following:
const user = new firebase.User(userData, userData.stsTokenManager, userData);
Property 'User' does not exist on type 'typeof firebase'.ts(2339)
Seems like I can reference the type but not instantiate it. I am using:
"firebase": "^7.14.3",
"firebase-admin": "^8.12.1",
Any workarounds on how to instantiate firebase.User that way with Typescript?
Bit late to the party, but this workaround worked for me:
Save user:
const userJson = JSON.stringify(currentUser.toJSON()) // Write userJson to diskLoad user:
// Read userJson from disk const userData = JSON.parse(userJson) const user = new firebase.User(userData, userData.stsTokenManager, userData) firebase.auth().updateCurrentUser(user)
Could this be documented as a public API so we can rely on it not changing in the future?
Seems to break as of firebase version 7.21.0. Works on firebase version 7.19.1
Hey folks,
I've filed b/169069711 to track this feature request internally. The modularization effort is ongoing - once we complete that we should be in a place where we can consider this feature request.
Hope that helps!
~Malcolm
Most helpful comment
Bit late to the party, but this workaround worked for me:
Save user:
Load user: