Skip to content

Commit

Permalink
aws-samples#52: Time frame corrected to refresh token soon to expire.
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoGabriel committed May 11, 2020
1 parent 7f69c69 commit 72823f0
Show file tree
Hide file tree
Showing 2 changed files with 902 additions and 972 deletions.
4 changes: 2 additions & 2 deletions src/lambda-edge/check-auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export const handler: CloudFrontRequestHandler = async (event) => {
if (!tokenUserName || !idToken) {
throw new Error('No valid credentials present in cookies');
}
// If the token has (nearly) expired and there is a refreshToken: refresh tokens
// If the token has expired or expires in less than 5 minutes and there is a refreshToken: refresh tokens
const { exp } = decodeToken(idToken);
if ((Date.now() / 1000) - (60 * 5) > exp && refreshToken) {
if ((Date.now() / 1000) > exp - (60 * 5) && refreshToken) {
return {
status: '307',
statusDescription: 'Temporary Redirect',
Expand Down

0 comments on commit 72823f0

Please sign in to comment.