@krak-stack/auth 0.1.65 → 0.1.67

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.
@@ -182,7 +182,7 @@ const useAuthProjectConfig = (baseUrl, searchString, projectConfig) => {
182
182
  : Schema.decodeUnknownSync(ExtraProjectPublicConfigSchema)(result.value);
183
183
  };
184
184
  const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
185
- const authLinkClassName = cn(buttonVariants({ variant: "link" }), "h-auto px-0 align-baseline");
185
+ const authLinkClassName = cn(buttonVariants({ variant: "link", size: null }), "h-auto align-baseline");
186
186
  const searchObject = (searchString) => Object.fromEntries(new URLSearchParams(searchString));
187
187
  const authMethodSearch = (searchString, method, email) => {
188
188
  const search = new URLSearchParams(searchString);
@@ -407,7 +407,7 @@ export function Signin(props) {
407
407
  method: selectedAuthMethod,
408
408
  otpSent: Boolean(otpSentTo),
409
409
  });
410
- }, children: [!emailSubmitted ? (_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", onKeyDown: (event) => {
410
+ }, children: [!emailSubmitted ? (_jsx(form.email, { label: m.field_email, type: "email", autoFocus: true, autoComplete: "email", onKeyDown: (event) => {
411
411
  if (event.key !== "Enter")
412
412
  return;
413
413
  event.preventDefault();
@@ -3,6 +3,7 @@ export type { AuthSession, AuthSessionWithOrganization, AuthSessionWithUser, Aut
3
3
  export { AuthClientConfig } from "../config";
4
4
  export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group";
5
5
  export { proxyAuthRequest } from "./proxy";
6
+ export type { ProxyAuthRequestOptions } from "./proxy";
6
7
  export { ActorRequired } from "./actor";
7
8
  export type { ActorConstraint } from "./actor";
8
9
  export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware";
@@ -1 +1,4 @@
1
- export declare const proxyAuthRequest: (request: Request, baseUrl: string | URL) => Promise<Response>;
1
+ export interface ProxyAuthRequestOptions {
2
+ cookieDomain?: string;
3
+ }
4
+ export declare const proxyAuthRequest: (request: Request, baseUrl: string | URL, options?: ProxyAuthRequestOptions) => Promise<Response>;
@@ -1,4 +1,5 @@
1
1
  const blockedRequestHeaders = [
2
+ "accept-encoding",
2
3
  "connection",
3
4
  "content-length",
4
5
  "forwarded",
@@ -12,6 +13,40 @@ const blockedRequestHeaders = [
12
13
  "upgrade",
13
14
  "cdn-loop",
14
15
  ];
16
+ const hostOnlyCookie = (cookie) => cookie.replace(/;\s*domain=[^;]*/gi, "");
17
+ const normalizedCookieDomain = (domain) => domain.trim().toLowerCase().replace(/^\.+|\.+$/g, "");
18
+ const sharedCookieDomain = (request, options) => {
19
+ if (!options?.cookieDomain)
20
+ return null;
21
+ const domain = normalizedCookieDomain(options.cookieDomain);
22
+ const hostname = new URL(request.url).hostname.toLowerCase();
23
+ if (!domain || (hostname !== domain && !hostname.endsWith(`.${domain}`))) {
24
+ return null;
25
+ }
26
+ return domain;
27
+ };
28
+ const cookieForDomain = (cookie, domain) => {
29
+ const hostOnly = hostOnlyCookie(cookie);
30
+ if (!domain || hostOnly.startsWith("__Host-"))
31
+ return hostOnly;
32
+ return `${hostOnly}; Domain=${domain}`;
33
+ };
34
+ const proxyResponse = async (request, response, options) => {
35
+ const headers = new Headers(response.headers);
36
+ const cookies = response.headers.getSetCookie();
37
+ const cookieDomain = sharedCookieDomain(request, options);
38
+ if (cookies.length > 0) {
39
+ headers.delete("set-cookie");
40
+ for (const cookie of cookies) {
41
+ headers.append("set-cookie", cookieForDomain(cookie, cookieDomain));
42
+ }
43
+ }
44
+ return new Response(response.body, {
45
+ status: response.status,
46
+ statusText: response.statusText,
47
+ headers,
48
+ });
49
+ };
15
50
  const forwardedUrl = (request) => {
16
51
  return new URL(request.url);
17
52
  };
@@ -29,7 +64,7 @@ const proxyHeaders = (request) => {
29
64
  headers.set("x-forwarded-proto", url.protocol.replace(":", ""));
30
65
  return headers;
31
66
  };
32
- export const proxyAuthRequest = (request, baseUrl) => {
67
+ export const proxyAuthRequest = async (request, baseUrl, options) => {
33
68
  const target = new URL(request.url);
34
69
  const authUrl = new URL(baseUrl);
35
70
  const init = {
@@ -43,5 +78,8 @@ export const proxyAuthRequest = (request, baseUrl) => {
43
78
  if (request.method !== "GET" && request.method !== "HEAD") {
44
79
  init.body = request.body;
45
80
  }
46
- return fetch(new Request(target, init), { redirect: "manual" });
81
+ const response = await fetch(new Request(target, init), {
82
+ redirect: "manual",
83
+ });
84
+ return proxyResponse(request, response, options);
47
85
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.1.65",
3
+ "version": "0.1.67",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [