From 012c377734a9a54a5355412c5396fc368af31c50 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 21 Jan 2017 00:17:23 +0100 Subject: [PATCH] Auto-refresh AWS credentials to prevent save errors --- app.coffee | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app.coffee b/app.coffee index cea0ae2..04ae2eb 100644 --- a/app.coffee +++ b/app.coffee @@ -49,11 +49,18 @@ $ -> signinCallback = (authResult) -> 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 IdentityPoolId: window.past3_config.identity_pool_id Logins: - 'accounts.google.com': authResult.Zi.id_token + 'accounts.google.com': googleIDToken AWS.config.credentials.get () -> $('#signin').modal 'hide' @@ -172,3 +179,8 @@ error = (err) -> ed = $('#errorDisplay') ed.find('.alert').text err 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