Last active
July 2, 2020 05:29
-
-
Save naramdash/1e305c3a7b794f73c8b6bd4d7a34238d to your computer and use it in GitHub Desktop.
AWS Amplify refreshSession (id: new, access: new, refresh: same)
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 function refresh() { | |
const { idToken, accessToken, refreshToken } = await Auth.currentSession(); | |
console.log('id: ', idToken.jwtToken); | |
console.log(); | |
console.log('access: ', accessToken.jwtToken); | |
console.log(); | |
console.log('refresh: ', refreshToken.token); | |
console.log(); | |
try { | |
const cognitoUser = await Auth.currentAuthenticatedUser(); | |
const currentSession = await Auth.currentSession(); | |
console.log(cognitoUser); | |
cognitoUser.refreshSession( | |
currentSession.refreshToken, | |
(err, session) => { | |
console.log('session', err, session); | |
const { | |
idToken: newId, | |
refreshToken: newRefresh, | |
accessToken: newAccess, | |
} = session; | |
console.log('id same?: ', idToken.jwtToken === newId.jwtToken); | |
console.log( | |
'access same?: ', | |
accessToken.jwtToken === newAccess.jwtToken, | |
); | |
console.log( | |
'refresh same?: ', | |
refreshToken.token === newRefresh.token, | |
); | |
console.log('new refreshToken', newRefresh.token); | |
}, | |
); | |
} catch (e) { | |
console.log('Unable to refresh Token', e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment