Skip to content

Commit

Permalink
10007: more sub vs custom:userId refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
TomElliottFlexion committed Jan 23, 2024
1 parent b4d38a3 commit b65c182
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const addExistingUserToCase = async ({
throw new UnauthorizedError('Unauthorized');
}

//TODO 10007: make sure this flow is also tested
const userIdFromCognito = await applicationContext
.getPersistenceGateway()
.getCognitoUserIdByEmail({
Expand Down
15 changes: 8 additions & 7 deletions web-api/src/persistence/cognito/getCognitoUserIdByEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ export const getCognitoUserIdByEmail = async ({
Username: email,
});

const customUserId = (
userFromCognito.UserAttributes?.find(
attribute => attribute.Name === 'custom:userId',
) || {}
).Value;
// replace with sub here
return customUserId || userFromCognito.Username;
const customUserId =
userFromCognito?.UserAttributes?.find(
element => element.Name === 'custom:userId',
)?.Value ||
userFromCognito?.UserAttributes?.find(element => element.Name === 'sub')
?.Value;

return customUserId;
} catch (e) {
return null;
}
Expand Down

0 comments on commit b65c182

Please sign in to comment.