* Which Category is your question related to? *
Auth
* What AWS Services are you utilizing? *
Cognito
* Provide additional details e.g. code snippets *
How do I get an updated idToken after updating user attributes:
let user = await Auth.currentAuthenticatedUser();
const result = await Auth.updateUserAttributes(user, {
'custom:merchant_id': merchant_id,
});
console.log(result); // SUCCESS
user = await Auth.currentAuthenticatedUser();
console.log(user);
This works as expected but it will not update ID (identification) token used by Amplify...
Now that old ID token is sent the claims in there are not updated, server receives the old claims.
Is there any way to refresh / regenerate the id token?
I think the data in server got updated but data in cache not updated
call this once to update the current cache
await Auth.currentAuthenticatedUser({ bypassCache: false });
This will give the updated attributes of the current authenticated user but not refresh the id/jwt token. I ended up doing this:
import {
Auth
} from 'aws-amplify';
class AuthHelper {
static async refreshSessionPromise(refreshToken) {
return new Promise(async (resolve, reject) => {
const user = await Auth.currentAuthenticatedUser();
return user.refreshSession(refreshToken, async (err, data) => {
if (err) {
reject(err);
} else {
resolve(data); // THIS IS YOUR REFRESHED ATTRIBUTES/GROUPS
}
});
});
}
static async refreshCurrentSession() {
const session = await Auth.currentSession();
return this.refreshSessionPromise(session.getRefreshToken());
}
}
export default AuthHelper;
Should be fixed now in the latest unstable release. Will be released to stable in the near future as well. Closing this issue.
Most helpful comment
This will give the updated attributes of the current authenticated user but not refresh the id/jwt token. I ended up doing this: