title: Persist Firebase user for Node.js client application
body: <p>I'm building a Node.js command-line interface (CLI) using Firebase 
  for authentication with the back end. I want to avoid making the user type their password every time they run a command. Instead, I want to implement a "login" flow that persists a credential to the filesystem that can be used for subsequent password-less authentication until the user "logs out".</p>
  
  <p>Basically what I'm looking for is the <a href="https://github.com/firebase/firebase-js-sdk" rel="nofollow noreferrer"><code>firebase</code> JavaScript SDK's</a> "auth state persistence" feature. Unfortunately that feature is not supported for Node.js; calling <code>setPersistence</code> with either <code>'local'</code> or <code>'session'</code> as the mode raises an error "The current environment does not support the specified persistence type."</p>
  
  <p>What's the easiest way to implement that feature "on my own"?</p>
  
  <p>I looked into how the SDK persists the user in a browser and basically it stringifies the user object and stores it localstorage. I can stringify the user object myself easily enough in Node.js (the instance has a <code>toJSON</code> method), but I can't figure out how to later de-serialize the string into an instance of <code>firebase.User</code>. I see <a href="https://github.com/firebase/firebase-js-sdk/blob/780c302fd6da799dafed45345b694a8a8a4a3c78/packages/auth/src/authuser.js#L2253" rel="nofollow noreferrer">this function in the source code</a> that looks like it'd do the trick. But that's not exposed externally on the SDK AFAIK.</p>