Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevents incorrectly removing idx message duplicates #1446

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 7.4.1

### Bug Fix

- [#1446](https://github.com/okta/okta-auth-js/pull/1446) Fix: prevents incorrectly removing idx message duplicates

## 7.4.0

### Features
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ require('@okta/okta-auth-js/polyfill');
The built polyfill bundle is also available on our global CDN. Include the following script in your HTML file to load before any other scripts:

```html
<script src="https://global.oktacdn.com/okta-auth-js/7.0.0/okta-auth-js.polyfill.js" type="text/javascript"></script>
<script src="https://global.oktacdn.com/okta-auth-js/7.4.1/okta-auth-js.polyfill.js" type="text/javascript"></script>
```

> :warning: The version shown in this sample may be older than the current version. We recommend using the highest version available
Expand Down Expand Up @@ -171,7 +171,7 @@ If you are using the JS on a web page from the browser, you can copy the `node_m
The built library bundle is also available on our global CDN. Include the following script in your HTML file to load before your application script:

```html
<script src="https://global.oktacdn.com/okta-auth-js/7.0.0/okta-auth-js.min.js" type="text/javascript"></script>
<script src="https://global.oktacdn.com/okta-auth-js/7.4.1/okta-auth-js.min.js" type="text/javascript"></script>
```

> :warning: The version shown in this sample may be older than the current version. We recommend using the highest version available
Expand Down Expand Up @@ -812,7 +812,7 @@ const config = {
};

const authClient = new OktaAuth(config);
const tokens = await authClient.token.getWithoutPrompt();
const { tokens } = await authClient.token.getWithoutPrompt();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolves #1407

authClient.tokenManager.setTokens(tokens); // storageProvider.setItem

```
Expand Down
3 changes: 2 additions & 1 deletion lib/idx/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ export function getMessagesFromResponse(idxResponse: IdxResponse, options: RunOp
const seen = {};
messages = messages.reduce((filtered, message) => {
const key = message.i18n?.key;
if (key && seen[key]) {
if (key && seen[key] && message.message === seen[key].message) {
return filtered;
}
seen[key] = message;
filtered = [...filtered, message] as never;
return filtered;
}, []);

return messages;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"name": "@okta/okta-auth-js",
"description": "The Okta Auth SDK",
"version": "7.4.0",
"version": "7.4.1",
"homepage": "https://github.com/okta/okta-auth-js",
"license": "Apache-2.0",
"main": "build/cjs/exports/default.js",
Expand Down
40 changes: 40 additions & 0 deletions test/spec/idx/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,46 @@ describe('idx/util', () => {
}]);
});

it('removes duplicate messages', () => {
const expected = [
{
class: 'ERROR',
i18n: {
key: 'security.access_denied'
},
message: 'You do not have permission to perform the requested action.'
},
{
class: 'ERROR',
i18n: {
key: 'security.access_denied'
},
message: 'some random text'
}
];

const rawIdxState = RawIdxResponseFactory.build({
messages: IdxMessagesFactory.build({
value: [
IdxErrorAccessDeniedFactory.build(),
IdxErrorAccessDeniedFactory.build(),
IdxErrorAccessDeniedFactory.build(),
IdxErrorAccessDeniedFactory.build({
message: 'some random text'
})
]
})
});
const idxResponse = IdxResponseFactory.build({
rawIdxState
});
const res = getMessagesFromResponse(idxResponse, {});
expect(res).toEqual(expected);

const genericRemRes = getMessagesFromResponse(idxResponse, { useGenericRemediator: true });
expect(genericRemRes).toEqual(expected);
});

describe('form level messages', () => {
let idxResponse;
beforeEach(() => {
Expand Down