Skip to content

Commit f5e4b6b

Browse files
authored
Merge pull request #123 from okta/sw-backport-122
Backport PR 122
2 parents c002c45 + 8041dde commit f5e4b6b

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 5.1.2
2+
3+
### Bug Fixes
4+
5+
- [#122](https://github.com/okta/okta-react/pull/122) Locks the SDK with installed okta-auth-js major version
6+
17
# 5.1.1
28

39
### Bug Fixes

env.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
const path = require('path');
22
const dotenv = require('dotenv');
33
const fs = require('fs');
4+
const semver = require('semver');
45

56
// Read information from package.json and expose as environment variables
67
const PACKAGE = require('./package.json');
78
process.env.PACKAGE_NAME = PACKAGE.name;
89
process.env.PACKAGE_VERSION = PACKAGE.version;
10+
const authJsVersion = PACKAGE.dependencies['@okta/okta-auth-js'];
11+
process.env.AUTH_JS_MAJOR_VERSION = semver.minVersion(authJsVersion).major;
912

1013
// Read environment variables from "testenv". Override environment vars if they are already set.
1114
const TESTENV = path.resolve(__dirname, 'testenv');

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"rollup-plugin-cleanup": "^3.2.1",
9393
"rollup-plugin-terser": "^7.0.2",
9494
"rollup-plugin-typescript2": "^0.29.0",
95+
"semver": "^7.3.5",
9596
"shelljs": "^0.8.4",
9697
"ts-jest": "^26.4.4",
9798
"typescript": "^4.0.5"
@@ -104,4 +105,4 @@
104105
"./",
105106
"test/e2e/harness"
106107
]
107-
}
108+
}

rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const commonPlugins = [
3232
}),
3333
replace({
3434
'process.env.PACKAGE_NAME': JSON.stringify(process.env.PACKAGE_NAME),
35-
'process.env.PACKAGE_VERSION': JSON.stringify(process.env.PACKAGE_VERSION)
35+
'process.env.PACKAGE_VERSION': JSON.stringify(process.env.PACKAGE_VERSION),
36+
'process.env.AUTH_JS_MAJOR_VERSION': JSON.stringify(process.env.AUTH_JS_MAJOR_VERSION)
3637
}),
3738
cleanup({
3839
extensions,

src/Security.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const Security: React.FC<{
3737
}
3838
return oktaAuth.authStateManager.getAuthState();
3939
});
40+
const [oktaAuthMajorVersion] = React.useState(() => {
41+
const majorVersion = oktaAuth?.userAgent?.split('/')[1]?.split('.')[0];
42+
return majorVersion;
43+
});
4044

4145
React.useEffect(() => {
4246
if (!oktaAuth || !restoreOriginalUri) {
@@ -77,6 +81,17 @@ const Security: React.FC<{
7781
return <OktaError error={err} />;
7882
}
7983

84+
85+
if (oktaAuthMajorVersion !== process.env.AUTH_JS_MAJOR_VERSION
86+
// skip in test as version and userAgent are dynamic
87+
&& process.env.NODE_ENV !== 'test') {
88+
const err = new AuthSdkError(`
89+
Passed in oktaAuth is not compatible with the SDK,
90+
okta-auth-js version ${process.env.AUTH_JS_MAJOR_VERSION}.x is the current supported version.
91+
`);
92+
return <OktaError error={err} />;
93+
}
94+
8095
return (
8196
<OktaContext.Provider value={{
8297
oktaAuth,

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11923,6 +11923,13 @@ semver@7.x, semver@^7.2.1, semver@^7.3.2:
1192311923
dependencies:
1192411924
lru-cache "^6.0.0"
1192511925

11926+
semver@^7.3.5:
11927+
version "7.3.5"
11928+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
11929+
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
11930+
dependencies:
11931+
lru-cache "^6.0.0"
11932+
1192611933
send@0.17.1:
1192711934
version "0.17.1"
1192811935
resolved "https://registry.yarnpkg.com/send/-/send-0.17.1.tgz#c1d8b059f7900f7466dd4938bdc44e11ddb376c8"

0 commit comments

Comments
 (0)