@@ -58,7 +58,8 @@ class Header extends Component {
5858 updateCollection : false ,
5959 fetchCollection : false ,
6060 socket : sockets ( ) ,
61- savedSettings : [ ]
61+ savedSettings : [ ] ,
62+ googleUser : undefined
6263 } ;
6364
6465 this . state . socket . on ( "update" , ( ) => {
@@ -200,10 +201,27 @@ class Header extends Component {
200201 //googleAuth.getAuthResponse().id_token;
201202 googleAuth . profileObj [ "uid" ] = googleAuth . getAuthResponse ( ) . id_token ;
202203 this . props . logging . login ( googleAuth . profileObj ) ;
203- this . setState ( { logMenuOpen : false } ) ;
204+ this . setState ( { logMenuOpen : false , googleUser : googleAuth } ) ;
204205
205206 this . props . projectActions . asyncUserProj ( this . props . user . uid ) ;
206207 this . props . collectionActions . asyncCollections ( this . props . user . uid ) ;
208+ this . setRefreshTime ( googleAuth . tokenObj . expires_at ) ;
209+ }
210+
211+ setRefreshTime = ( time ) => {
212+ const oneMinute = 60 * 1000 ;
213+ let expiryTime = Math . max (
214+ oneMinute * 5 , //Default of 5 minutes
215+ time - Date . now ( ) - oneMinute * 5 // give 5 mins of breathing room
216+ ) ;
217+ setTimeout ( this . refreshToken , expiryTime ) ;
218+ }
219+
220+ refreshToken = ( ) => {
221+ this . state . googleUser . reloadAuthResponse ( ) . then ( ( authResponse ) => {
222+ this . props . logging . refreshToken ( authResponse . id_token ) ;
223+ this . setRefreshTime ( authResponse . expires_at ) ;
224+ } ) ;
207225 }
208226
209227 /**
@@ -399,7 +417,7 @@ class Header extends Component {
399417 if ( ! this . state . viewOnly ) {
400418 this . props . actions . refresh ( text , this . props . user ? this . props . user . uid : "anon" ) ;
401419 }
402- this . setState ( { spinnerOpen : false } ) ;
420+ this . setState ( { spinnerOpen : false , saveOpen : false } ) ;
403421 this . state . socket . emit ( "save" ) ;
404422 return true ;
405423 } ) ;
0 commit comments