diff --git a/CHANGELOG.md b/CHANGELOG.md index 834c0c25..6d95590b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 5.1.2 + +### Bug Fixes + +- [#122](https://github.com/okta/okta-react/pull/122) Locks the SDK with installed okta-auth-js major version + # 5.1.1 ### Bug Fixes diff --git a/env.js b/env.js index 0a2945f6..930e0fb0 100644 --- a/env.js +++ b/env.js @@ -1,11 +1,14 @@ const path = require('path'); const dotenv = require('dotenv'); const fs = require('fs'); +const semver = require('semver'); // Read information from package.json and expose as environment variables const PACKAGE = require('./package.json'); process.env.PACKAGE_NAME = PACKAGE.name; process.env.PACKAGE_VERSION = PACKAGE.version; +const authJsVersion = PACKAGE.dependencies['@okta/okta-auth-js']; +process.env.AUTH_JS_MAJOR_VERSION = semver.minVersion(authJsVersion).major; // Read environment variables from "testenv". Override environment vars if they are already set. const TESTENV = path.resolve(__dirname, 'testenv'); diff --git a/package.json b/package.json index fea7b483..1773a5e1 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-terser": "^7.0.2", "rollup-plugin-typescript2": "^0.29.0", + "semver": "^7.3.5", "shelljs": "^0.8.4", "ts-jest": "^26.4.4", "typescript": "^4.0.5" @@ -104,4 +105,4 @@ "./", "test/e2e/harness" ] -} \ No newline at end of file +} diff --git a/rollup.config.js b/rollup.config.js index a42b6398..df17cea3 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -32,7 +32,8 @@ const commonPlugins = [ }), replace({ 'process.env.PACKAGE_NAME': JSON.stringify(process.env.PACKAGE_NAME), - 'process.env.PACKAGE_VERSION': JSON.stringify(process.env.PACKAGE_VERSION) + 'process.env.PACKAGE_VERSION': JSON.stringify(process.env.PACKAGE_VERSION), + 'process.env.AUTH_JS_MAJOR_VERSION': JSON.stringify(process.env.AUTH_JS_MAJOR_VERSION) }), cleanup({ extensions, diff --git a/src/Security.tsx b/src/Security.tsx index 93c80071..32552a76 100644 --- a/src/Security.tsx +++ b/src/Security.tsx @@ -37,6 +37,10 @@ const Security: React.FC<{ } return oktaAuth.authStateManager.getAuthState(); }); + const [oktaAuthMajorVersion] = React.useState(() => { + const majorVersion = oktaAuth?.userAgent?.split('/')[1]?.split('.')[0]; + return majorVersion; + }); React.useEffect(() => { if (!oktaAuth || !restoreOriginalUri) { @@ -77,6 +81,17 @@ const Security: React.FC<{ return ; } + + if (oktaAuthMajorVersion !== process.env.AUTH_JS_MAJOR_VERSION + // skip in test as version and userAgent are dynamic + && process.env.NODE_ENV !== 'test') { + const err = new AuthSdkError(` + Passed in oktaAuth is not compatible with the SDK, + okta-auth-js version ${process.env.AUTH_JS_MAJOR_VERSION}.x is the current supported version. + `); + return ; + } + return (