Skip to content

Commit 4a55e07

Browse files
authored
fix: make doesSessionExist refresh if front-token expired (#176)
1 parent 6c6e07b commit 4a55e07

File tree

12 files changed

+278
-15
lines changed

12 files changed

+278
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [14.0.3] - 2022-11-24
11+
12+
### Fixes
13+
14+
- doesSessionExist now refreshes the session if it detects an expired access token
15+
1016
## [14.0.2] - 2022-10-24
1117

1218
### Fixes

bundle/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/fetch.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/recipeImplementation.js

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/version.d.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/version.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ts/fetch.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,7 @@ function parseFrontToken(frontToken: string): { uid: string; ate: number; up: an
824824

825825
export async function getFrontToken(): Promise<string | null> {
826826
logDebugMessage("getFrontToken: called");
827-
// we do not call doesSessionExist here cause the user might override that
828-
// function here and then it may break the logic of our original implementation.
827+
// we do not call doesSessionExist here because that directly calls this function.
829828
if (!((await getIdRefreshToken(true)).status === "EXISTS")) {
830829
logDebugMessage("getFrontToken: Returning because sIRTFrontend != EXISTS");
831830
return null;

lib/ts/recipeImplementation.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ClaimValidationError,
88
ResponseWithBody
99
} from "./types";
10-
import AuthHttpRequest, { FrontToken, getIdRefreshToken } from "./fetch";
10+
import AuthHttpRequest, { FrontToken, getIdRefreshToken, onUnauthorisedResponse } from "./fetch";
1111
import { interceptorFunctionRequestFulfilled, responseInterceptor, responseErrorInterceptor } from "./axios";
1212
import { supported_fdi } from "./version";
1313
import { logDebugMessage } from "./logger";
@@ -97,7 +97,24 @@ export default function RecipeImplementation(recipeImplInput: {
9797
},
9898
doesSessionExist: async function(_: { userContext: any }): Promise<boolean> {
9999
logDebugMessage("doesSessionExist: called");
100-
return (await getIdRefreshToken(true)).status === "EXISTS";
100+
101+
const tokenInfo = await FrontToken.getTokenInfo();
102+
103+
// The above includes getIdRefreshToken(true), which would call refresh if the FE cookies were cleared for some reason
104+
if (tokenInfo === undefined) {
105+
logDebugMessage("doesSessionExist: access token does not exist locally");
106+
return false;
107+
}
108+
109+
if (tokenInfo.ate < Date.now()) {
110+
logDebugMessage("doesSessionExist: access token expired. Refreshing session");
111+
112+
const preRequestIdToken = await getIdRefreshToken(false);
113+
const refresh = await onUnauthorisedResponse(preRequestIdToken);
114+
return refresh.result === "RETRY";
115+
}
116+
117+
return true;
101118
},
102119
signOut: async function(input: { userContext: any }): Promise<void> {
103120
logDebugMessage("signOut: called");

lib/ts/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
* License for the specific language governing permissions and limitations
1313
* under the License.
1414
*/
15-
export const package_version = "14.0.2";
15+
export const package_version = "14.0.3";
1616

1717
export const supported_fdi = ["1.8", "1.9", "1.10", "1.11", "1.12", "1.13", "1.14", "1.15"];

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)