Skip to content

Commit d53ac30

Browse files
chore (cleanup): cleanup session management
1 parent 9baf4b0 commit d53ac30

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

public/assets/boot/ctrl_boot_frontoffice.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default async function main() {
1515
setup_blue_death_screen(),
1616
setup_history(),
1717
setup_polyfill(),
18-
setup_iframe(),
1918
]);
2019

2120
await Promise.all([ // procedure with dependency on config
@@ -107,22 +106,3 @@ async function setup_polyfill() {
107106
await loadJS(import.meta.url, "../lib/polyfill.js");
108107
}
109108
}
110-
111-
// In safari and duck duck go browser, cross domain iframe cannot inject cookies,
112-
// see https://support.apple.com/en-au/guide/safari/sfri40732/mac
113-
// hopefully one day, they provide support for partitioned cookie and we can remove this code
114-
// but until that happens we had to find a way to inject authorisation within ../lib/ajax.js
115-
async function setup_iframe() {
116-
if (window.self === window.top) return;
117-
118-
window.addEventListener("pagechange", async() => {
119-
if (location.hash === "") return; // happy path
120-
121-
const token = new URLSearchParams(location.hash.replace(new RegExp("^#"), "?")).get("bearer");
122-
if (token) window.BEARER_TOKEN = token;
123-
124-
if (location.pathname === toHref("/logout")) {
125-
delete window.BEARER_TOKEN;
126-
}
127-
});
128-
}

public/assets/model/session.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@ import rxjs from "../lib/rx.js";
22
import ajax from "../lib/ajax.js";
33
import { forwardURLParams } from "../lib/path.js";
44

5-
export function createSession(authenticationRequest) {
6-
return ajax({
7-
method: "POST",
8-
url: withShare("./api/session"),
9-
body: authenticationRequest,
10-
responseType: "json",
11-
});
12-
}
13-
145
export function getSession() {
156
return ajax({
167
url: withShare("api/session"),
@@ -21,11 +12,30 @@ export function getSession() {
2112
);
2213
}
2314

15+
export function createSession(authenticationRequest) {
16+
return ajax({
17+
method: "POST",
18+
url: withShare("api/session"),
19+
body: authenticationRequest,
20+
responseType: "json",
21+
}).pipe(rxjs.tap(({ responseHeaders }) => {
22+
if (responseHeaders.bearer) window.BEARER_TOKEN = responseHeaders.bearer; // see ctrl_boot_frontoffice.js -> setup_iframe
23+
}));
24+
}
25+
2426
export function deleteSession() {
2527
return ajax({
2628
url: withShare("api/session"),
2729
method: "DELETE"
28-
});
30+
}).pipe(rxjs.tap(() => {
31+
delete window.BEARER_TOKEN;
32+
}));
2933
}
3034

35+
window.addEventListener("pagechange", async() => {
36+
if (location.hash === "") return; // happy path
37+
const token = new URLSearchParams(location.hash.replace(new RegExp("^#"), "?")).get("bearer");
38+
if (token) window.BEARER_TOKEN = token;
39+
});
40+
3141
const withShare = (url) => forwardURLParams(url, ["share"]);

public/assets/pages/connectpage/ctrl_form.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ export default async function(render) {
199199
rxjs.tap(() => toggleLoader(true)),
200200
rxjs.mergeMap(() => createSession(formData)),
201201
rxjs.tap(({ responseJSON, responseHeaders }) => {
202-
if (responseHeaders.bearer) window.BEARER_TOKEN = responseHeaders.bearer; // see ctrl_boot_frontoffice.js -> setup_iframe
203202
let redirectURL = toHref("/files/");
204203
const GET = getURLParams();
205204
if (GET["next"]) redirectURL = GET["next"];

0 commit comments

Comments
 (0)