@krak-stack/auth 0.1.32 → 0.1.33
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.
- package/dist/components/utils.js +3 -2
- package/dist/extra/schema.js +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/proxy.d.ts +1 -0
- package/dist/server/proxy.js +41 -0
- package/package.json +1 -1
package/dist/components/utils.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export const isRecord = (value) => typeof value === "object" && value !== null;
|
|
2
|
+
const isAssetPath = (path) => path.startsWith("/api/assets/") || path.startsWith("/api/auth/assets/");
|
|
2
3
|
export const assetPath = (value) => {
|
|
3
4
|
if (!value?.trim())
|
|
4
5
|
return null;
|
|
5
6
|
try {
|
|
6
7
|
const url = new URL(value);
|
|
7
|
-
return url.pathname
|
|
8
|
+
return isAssetPath(url.pathname) ? url.pathname : value;
|
|
8
9
|
}
|
|
9
10
|
catch {
|
|
10
11
|
return value;
|
|
@@ -14,7 +15,7 @@ export const assetUrl = (value, baseUrl) => {
|
|
|
14
15
|
const path = value?.trim();
|
|
15
16
|
if (!path)
|
|
16
17
|
return "";
|
|
17
|
-
if (!path
|
|
18
|
+
if (!isAssetPath(path))
|
|
18
19
|
return path;
|
|
19
20
|
if (!baseUrl?.trim())
|
|
20
21
|
return path;
|
package/dist/extra/schema.js
CHANGED
|
@@ -215,6 +215,11 @@ export const ExtraUploadedAsset = Schema.Struct({
|
|
|
215
215
|
identifier: "ExtraUploadedAsset",
|
|
216
216
|
title: "Extra uploaded asset",
|
|
217
217
|
description: "Stable public asset URL returned after an image upload.",
|
|
218
|
+
examples: [
|
|
219
|
+
{
|
|
220
|
+
url: "https://auth.example.com/api/auth/assets/logos/organizations/logo.png",
|
|
221
|
+
},
|
|
222
|
+
],
|
|
218
223
|
});
|
|
219
224
|
export class ExtraBadRequest extends Schema.ErrorClass("ExtraBadRequest")({
|
|
220
225
|
_tag: Schema.tag("ExtraBadRequest"),
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./schema";
|
|
|
2
2
|
export { AuthApi } from "./api";
|
|
3
3
|
export { AuthService, type AuthServiceLayerOptions } from "./service";
|
|
4
4
|
export { AuthClientConfig } from "./config";
|
|
5
|
+
export { proxyAuthRequest } from "./server/proxy";
|
|
5
6
|
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, UserButton, type AuthUiClient, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type UserButtonDialog, } from "./components";
|
|
6
7
|
export * as BetterAuth from "./better-auth";
|
|
7
8
|
export * as Extra from "./extra";
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./schema";
|
|
|
2
2
|
export { AuthApi } from "./api";
|
|
3
3
|
export { AuthService } from "./service";
|
|
4
4
|
export { AuthClientConfig } from "./config";
|
|
5
|
+
export { proxyAuthRequest } from "./server/proxy";
|
|
5
6
|
export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, UserButton, } from "./components";
|
|
6
7
|
export * as BetterAuth from "./better-auth";
|
|
7
8
|
export * as Extra from "./extra";
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { AuthService } from "../service";
|
|
2
2
|
export { AuthClientConfig } from "../config";
|
|
3
3
|
export { ServerApi, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api";
|
|
4
|
+
export { proxyAuthRequest } from "./proxy";
|
|
4
5
|
export type { ServerActiveOrganization, ServerMembersResponse, ServerOrganizationsResponse, ServerUsersResponse, } from "./schema";
|
|
5
6
|
export type { Member, Organization, OrganizationMetadata, User, } from "../schema";
|
package/dist/server/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const proxyAuthRequest: (request: Request, baseUrl: string | URL) => Promise<Response>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const blockedRequestHeaders = [
|
|
2
|
+
"connection",
|
|
3
|
+
"content-length",
|
|
4
|
+
"forwarded",
|
|
5
|
+
"host",
|
|
6
|
+
"keep-alive",
|
|
7
|
+
"proxy-authenticate",
|
|
8
|
+
"proxy-authorization",
|
|
9
|
+
"te",
|
|
10
|
+
"trailer",
|
|
11
|
+
"transfer-encoding",
|
|
12
|
+
"upgrade",
|
|
13
|
+
"cdn-loop",
|
|
14
|
+
];
|
|
15
|
+
const proxyHeaders = (request) => {
|
|
16
|
+
const headers = new Headers(request.headers);
|
|
17
|
+
for (const header of blockedRequestHeaders)
|
|
18
|
+
headers.delete(header);
|
|
19
|
+
for (const header of Array.from(headers.keys())) {
|
|
20
|
+
if (header.startsWith("cf-") || header.startsWith("x-forwarded-")) {
|
|
21
|
+
headers.delete(header);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return headers;
|
|
25
|
+
};
|
|
26
|
+
export const proxyAuthRequest = (request, baseUrl) => {
|
|
27
|
+
const target = new URL(request.url);
|
|
28
|
+
const authUrl = new URL(baseUrl);
|
|
29
|
+
const init = {
|
|
30
|
+
headers: proxyHeaders(request),
|
|
31
|
+
method: request.method,
|
|
32
|
+
};
|
|
33
|
+
target.protocol = authUrl.protocol;
|
|
34
|
+
target.host = authUrl.host;
|
|
35
|
+
target.username = authUrl.username;
|
|
36
|
+
target.password = authUrl.password;
|
|
37
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
38
|
+
init.body = request.body;
|
|
39
|
+
}
|
|
40
|
+
return fetch(new Request(target, init), { redirect: "manual" });
|
|
41
|
+
};
|