ios - Firebase re-authentication required -


we working on ios app using google authenticate firebase. according https://www.firebase.com/docs/ios/guide/user-auth.html#section-login firebase says auth tokens expire every 24 hours. wondering if following scenario need consider:

  1. user authenticates google , firebase
  2. our app gets firebase auth token expires in 24 hours
  3. user closes our ios app
  4. 1 minute before firebase auth token expires, user reopens app
  5. a minute later make request firebase. auth token has expired.

it seems have reauthenticate firebase observing authentication changes per https://www.firebase.com/docs/ios/guide/user-auth.html#section-monitoring-authentication. have re-issue same request firebase #5 above? seems reauthenticate in cancelblock:

[ref observeeventtype:feventtypevalue withblock:^(fdatasnapshot *snapshot) {     nslog(@"%@", snapshot.value); } withcancelblock:^(nserror *error) {     nslog(@"%@", error.description);     // reauthenticate , re-issue request? }]; 

this not ideal because have write code everywhere make request.

what best practices deal scenario? firebase automatically refresh auth token when it's close expiry?

obviously, question regarding old version of firebase , sdk. current version of firebase (3.x) makes easier since firebase remembers how user last logged in app.

so should call firapp.configure() e.g. in application: didfinishlaunchingwithoptions launchoptions: , add state listener @ launch of app like

firauth.auth()?.addstatedidchangelistener() { (auth, firuser) in  // firuser, e.g. update ui } 

the listener automatically invoked around time of application launch firebase whenever changes user , tokens handled in background firebase, i.e. don't have deal expired tokens. (it may more complex if use custom auth system).


Comments