mirror of
https://github.com/Luzifer/past3.git
synced 2024-12-22 20:31:16 +00:00
Auto-refresh AWS credentials to prevent save errors
This commit is contained in:
parent
5e25d393df
commit
012c377734
1 changed files with 13 additions and 1 deletions
14
app.coffee
14
app.coffee
|
@ -49,11 +49,18 @@ $ ->
|
||||||
|
|
||||||
signinCallback = (authResult) ->
|
signinCallback = (authResult) ->
|
||||||
if authResult.Zi.id_token
|
if authResult.Zi.id_token
|
||||||
|
getAWSCredentials authResult.Zi.id_token
|
||||||
|
|
||||||
|
window.past3_credential_refresh = window.setInterval () ->
|
||||||
|
if new Date(AWS.config.credentials.expireTime - 300000) < new Date()
|
||||||
|
refreshGoogleLogin()
|
||||||
|
, 10000
|
||||||
|
|
||||||
|
getAWSCredentials = (googleIDToken) ->
|
||||||
AWS.config.credentials = new AWS.CognitoIdentityCredentials
|
AWS.config.credentials = new AWS.CognitoIdentityCredentials
|
||||||
IdentityPoolId: window.past3_config.identity_pool_id
|
IdentityPoolId: window.past3_config.identity_pool_id
|
||||||
Logins:
|
Logins:
|
||||||
'accounts.google.com': authResult.Zi.id_token
|
'accounts.google.com': googleIDToken
|
||||||
|
|
||||||
AWS.config.credentials.get () ->
|
AWS.config.credentials.get () ->
|
||||||
$('#signin').modal 'hide'
|
$('#signin').modal 'hide'
|
||||||
|
@ -172,3 +179,8 @@ error = (err) ->
|
||||||
ed = $('#errorDisplay')
|
ed = $('#errorDisplay')
|
||||||
ed.find('.alert').text err
|
ed.find('.alert').text err
|
||||||
ed.show()
|
ed.show()
|
||||||
|
|
||||||
|
refreshGoogleLogin = () ->
|
||||||
|
console.log "Refreshing Google login / AWS credentials to keep editor working"
|
||||||
|
gapi.auth2.getAuthInstance().currentUser.get().reloadAuthResponse().then (data) ->
|
||||||
|
getAWSCredentials data.id_token
|
||||||
|
|
Loading…
Reference in a new issue