Created
July 24, 2023 06:24
-
-
Save maskaravivek/b9eae0266276839441a4413f1e390851 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async jwt({ token, user, account }) { | |
if (account && user) { | |
if (account['provider'] === 'cognito') { | |
token.accessToken = account?.access_token; | |
var tokenParsed = JSON.parse(Buffer.from(account.id_token.split('.')[1], 'base64').toString()); | |
token.username = tokenParsed['cognito:username']; | |
token.refreshToken = account?.refresh_token; | |
token.accessTokenExpires = account.expires_at * 1000; | |
} | |
} | |
// Return previous token if the access token has not expired yet | |
if ((Date.now()) < (token.accessTokenExpires ?? 0)) { | |
return token; | |
} | |
// Access token has expired, try to update it | |
return refreshAccessToken(token); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment