@krak-stack/auth 0.1.69 → 0.1.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,15 +7,14 @@ import { authClientApi } from "./auth-client-api";
|
|
|
7
7
|
import { parseRoleList } from "../roles";
|
|
8
8
|
const KrakstackAuthContext = createContext(null);
|
|
9
9
|
const PROJECT_CONTEXT_COOKIE = "krakstack-auth.project_context";
|
|
10
|
-
const sessionRevalidationEvents = ["focus", "pageshow"];
|
|
11
10
|
export const listenForSessionRevalidation = (target, revalidate) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const onPageShow = (event) => {
|
|
12
|
+
if ("persisted" in event && event.persisted === true)
|
|
13
|
+
revalidate();
|
|
14
|
+
};
|
|
15
|
+
target.addEventListener("pageshow", onPageShow);
|
|
15
16
|
return () => {
|
|
16
|
-
|
|
17
|
-
target.removeEventListener(event, revalidate);
|
|
18
|
-
}
|
|
17
|
+
target.removeEventListener("pageshow", onPageShow);
|
|
19
18
|
};
|
|
20
19
|
};
|
|
21
20
|
const setProjectContextCookie = (projectId) => {
|
package/dist/server/proxy.js
CHANGED
|
@@ -55,6 +55,8 @@ const proxyResponse = async (request, response, options) => {
|
|
|
55
55
|
const forwardedUrl = (request) => {
|
|
56
56
|
return new URL(request.url);
|
|
57
57
|
};
|
|
58
|
+
const preservesOAuthOrigin = (pathname) => pathname === "/api/auth/sign-in/social" ||
|
|
59
|
+
pathname.startsWith("/api/auth/callback/");
|
|
58
60
|
const proxyHeaders = (request) => {
|
|
59
61
|
const headers = new Headers(request.headers);
|
|
60
62
|
const url = forwardedUrl(request);
|
|
@@ -67,8 +69,10 @@ const proxyHeaders = (request) => {
|
|
|
67
69
|
}
|
|
68
70
|
headers.set("x-forwarded-host", url.host);
|
|
69
71
|
headers.set("x-forwarded-proto", url.protocol.replace(":", ""));
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
if (preservesOAuthOrigin(url.pathname)) {
|
|
73
|
+
headers.set("x-krakstack-forwarded-host", url.host);
|
|
74
|
+
headers.set("x-krakstack-forwarded-proto", url.protocol.replace(":", ""));
|
|
75
|
+
}
|
|
72
76
|
return headers;
|
|
73
77
|
};
|
|
74
78
|
export const proxyAuthRequest = async (request, baseUrl, options) => {
|