Clear AWS Credentials Cache
To be able to upload our files to S3 we needed to get the AWS credentials first. And the AWS JS SDK saves those credentials in our browser’s Local Storage.
But we need to make sure that we clear out those credentials when we logout. If we don’t, the next user that logs in on the same browser, might end up with the incorrect credentials.
To do that let’s replace the signOutUser
method in our src/libs/awsLib.js
with this:
export function signOutUser() {
const currentUser = getCurrentUser();
if (currentUser !== null) {
currentUser.signOut();
}
if (AWS.config.credentials) {
AWS.config.credentials.clearCachedId();
AWS.config.credentials = new AWS.CognitoIdentityCredentials({});
}
}
Here we are clearing the AWS JS SDK cache and resetting the credentials that it saves in the browser’s Local Storage.
Next up we are going to allow users to see a list of the notes they’ve created.
If you liked this post, please subscribe to our newsletter and give us a star on GitHub.
For help and discussion
Comments on this chapterFor reference, here is the code so far
Frontend Source :clear-aws-credentials-cache