Skip to content

Commit

Permalink
fix: use exp JWT value instead of value from x-session-lifetime header
Browse files Browse the repository at this point in the history
  • Loading branch information
lfleischmann committed Sep 29, 2023
1 parent 7c52dae commit df7940e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion frontend/frontend-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"typescript": "^4.9.5"
},
"dependencies": {
"@types/js-cookie": "^3.0.3"
"@types/js-cookie": "^3.0.3",
"jose": "^4.14.6"
}
}
8 changes: 6 additions & 2 deletions frontend/frontend-sdk/src/lib/client/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SessionState } from "../state/session/SessionState";
import { PasscodeState } from "../state/users/PasscodeState";
import { Dispatcher } from "../events/Dispatcher";
import { Cookie } from "../Cookie";
import { decodeJwt } from "jose";

/**
* This class wraps an XMLHttpRequest to maintain compatibility with the fetch API.
Expand Down Expand Up @@ -216,8 +217,11 @@ class HttpClient {

if (jwt) {
const secure = !!this.api.match("^https://");
const expires = new Date(new Date().getTime() + expirationSeconds * 1000);
this.cookie.setAuthCookie(jwt, { secure, expires });
const decodedJwt = decodeJwt(jwt);
this.cookie.setAuthCookie(jwt, {
secure,
expires: new Date(decodedJwt.exp * 1000),
});
}

this.passcodeState.read().reset(userID).write();
Expand Down
11 changes: 6 additions & 5 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit df7940e

Please sign in to comment.