@krak-stack/auth 0.1.66 → 0.1.68

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.
@@ -5,7 +5,7 @@ import { Effect, Schema } from "effect";
5
5
  import { AsyncResult, Atom } from "effect/unstable/reactivity";
6
6
  import { useState } from "react";
7
7
  import { toast } from "sonner";
8
- import { ImageField, SingleSearchableSelectField, SubmitButton, SubmitError, TextField, } from "@/components/ui/effect-form";
8
+ import { ImageField, SingleSearchableSelectField, SubmitButton, SubmitError, TextField, } from "@krak-stack/registry/effect-form";
9
9
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
10
10
  import { AdminCreateOrganizationPayload, } from "../admin/schema";
11
11
  import { authClientApi } from "./auth-client-api";
@@ -1,5 +1,5 @@
1
1
  import type { ValidateFromPath } from "@tanstack/react-router";
2
- import { type TableParams } from "@/components/ui/data-table";
2
+ import { type TableParams } from "@krak-stack/registry/data-table";
3
3
  export declare function AdminOrganizationsTable({ from, reloadKey, search, }: {
4
4
  from?: ValidateFromPath;
5
5
  reloadKey?: number;
@@ -5,9 +5,9 @@ import { Atom, AsyncResult } from "effect/unstable/reactivity";
5
5
  import { Building2, Pencil, Trash2 } from "lucide-react";
6
6
  import { useState } from "react";
7
7
  import { toast } from "sonner";
8
- import { DataTable, DataTableListSummary, } from "@/components/ui/data-table";
9
- import { ErrorMessage } from "@/components/ui/effect-form";
10
- import { AppBrand } from "@/components/ui/app-brand";
8
+ import { DataTable, DataTableListSummary, } from "@krak-stack/registry/data-table";
9
+ import { ErrorMessage } from "@krak-stack/registry/effect-form";
10
+ import { AppBrand } from "@krak-stack/registry/app-brand";
11
11
  import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
12
12
  import { AdminOrganizationForm } from "./admin-organization-form";
13
13
  import { authClientApi } from "./auth-client-api";
@@ -1,5 +1,5 @@
1
1
  import { type ValidateFromPath } from "@tanstack/react-router";
2
- import { type TableParams } from "@/components/ui/data-table";
2
+ import { type TableParams } from "@krak-stack/registry/data-table";
3
3
  export declare function AdminUsersTable({ from, reloadKey, search, }: {
4
4
  from?: ValidateFromPath;
5
5
  reloadKey?: number;
@@ -5,9 +5,9 @@ import {} from "@tanstack/react-table";
5
5
  import { Atom, AsyncResult } from "effect/unstable/reactivity";
6
6
  import { Ban, Building2, Loader2, ShieldOff, UserCog, UserIcon, } from "lucide-react";
7
7
  import { useState } from "react";
8
- import { DataTable, DataTableListSummary, } from "@/components/ui/data-table";
9
- import { ErrorMessage } from "@/components/ui/effect-form";
10
- import { AppBrand } from "@/components/ui/app-brand";
8
+ import { DataTable, DataTableListSummary, } from "@krak-stack/registry/data-table";
9
+ import { ErrorMessage } from "@krak-stack/registry/effect-form";
10
+ import { AppBrand } from "@krak-stack/registry/app-brand";
11
11
  import { Badge } from "@/components/ui/badge";
12
12
  import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
13
13
  import { authClientApi } from "./auth-client-api";
@@ -3,7 +3,7 @@ import { useAtomSet, useAtomValue } from "@effect/atom-react";
3
3
  import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
4
4
  import { Effect, Schema } from "effect";
5
5
  import { useRef, useState } from "react";
6
- import { CheckboxField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@/components/ui/effect-form";
6
+ import { CheckboxField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
7
7
  import { parseApiKeyReferrers, updateApiKey } from "./api-key";
8
8
  import { ApiKeyPermissions } from "./api-key-permissions";
9
9
  import { apiKeyReferrers } from "./api-key-referrers";
@@ -9,7 +9,7 @@ import { KeyRound, Loader2, Mail } from "lucide-react";
9
9
  import { useEffect, useState } from "react";
10
10
  import { Button, buttonVariants } from "@/components/ui/button";
11
11
  import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card";
12
- import { CheckboxField, ErrorMessage, SubmitError, TextField, effectFormMessages, } from "@/components/ui/effect-form";
12
+ import { CheckboxField, ErrorMessage, SubmitError, TextField, effectFormMessages, } from "@krak-stack/registry/effect-form";
13
13
  import { Field, FieldLabel } from "@/components/ui/field";
14
14
  import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, } from "@/components/ui/input-otp";
15
15
  import { authClientApi } from "./auth-client-api";
@@ -5,7 +5,7 @@ import { Atom } from "effect/unstable/reactivity";
5
5
  import { Check, Loader2, Mail, ShieldAlert } from "lucide-react";
6
6
  import { useEffect, useState } from "react";
7
7
  import { Button } from "@/components/ui/button";
8
- import { CopyButton } from "@/components/ui/copy-button";
8
+ import { CopyButton } from "@krak-stack/registry/copy-button";
9
9
  import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card";
10
10
  import { useKrakstackAuth } from "./auth-provider";
11
11
  import { isInvitationExpired, useInvitationExpirationClock, } from "./invitation-expiration";
@@ -7,15 +7,15 @@ import { Effect, Option, Schema } from "effect";
7
7
  import { AsyncResult, Atom } from "effect/unstable/reactivity";
8
8
  import { ArrowLeft, Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
9
9
  import { createContext, useContext, useEffect, useEffectEvent, useRef, useState, } from "react";
10
- import { DataTable, DataTableRelationshipCell, } from "@/components/ui/data-table";
11
- import { ErrorMessage, ImageField, SelectField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@/components/ui/effect-form";
12
- import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
13
- import { AppBrand } from "@/components/ui/app-brand";
10
+ import { DataTable, DataTableRelationshipCell, } from "@krak-stack/registry/data-table";
11
+ import { ErrorMessage, ImageField, SelectField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
12
+ import { EditingLocaleSwitcher } from "@krak-stack/registry/editing-locale-switcher";
13
+ import { AppBrand } from "@krak-stack/registry/app-brand";
14
14
  import { Field, FieldLabel, FieldSet } from "@/components/ui/field";
15
15
  import { Input } from "@/components/ui/input";
16
16
  import { Badge } from "@/components/ui/badge";
17
17
  import { Button } from "@/components/ui/button";
18
- import { CopyButton } from "@/components/ui/copy-button";
18
+ import { CopyButton } from "@krak-stack/registry/copy-button";
19
19
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
20
20
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
21
21
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
@@ -8,12 +8,12 @@ import { AsyncResult, Atom } from "effect/unstable/reactivity";
8
8
  import { ArrowLeft, Building2, KeyRound, Loader2, LogOutIcon, Pencil, Plus, ShieldCheck, StopCircle, Trash2, UserCircleIcon, Users, UserIcon, } from "lucide-react";
9
9
  import { QRCode } from "react-qr-code";
10
10
  import { createContext, useContext, useRef, useState, } from "react";
11
- import { DataTable } from "@/components/ui/data-table";
12
- import { AppBrand } from "@/components/ui/app-brand";
13
- import { effectFormMessages, ImageField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@/components/ui/effect-form";
11
+ import { DataTable } from "@krak-stack/registry/data-table";
12
+ import { AppBrand } from "@krak-stack/registry/app-brand";
13
+ import { effectFormMessages, ImageField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
14
14
  import { Badge } from "@/components/ui/badge";
15
15
  import { Button } from "@/components/ui/button";
16
- import { CopyButton } from "@/components/ui/copy-button";
16
+ import { CopyButton } from "@krak-stack/registry/copy-button";
17
17
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
18
18
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
19
19
  import { Separator } from "@/components/ui/separator";
@@ -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>;
@@ -14,13 +14,31 @@ const blockedRequestHeaders = [
14
14
  "cdn-loop",
15
15
  ];
16
16
  const hostOnlyCookie = (cookie) => cookie.replace(/;\s*domain=[^;]*/gi, "");
17
- const proxyResponse = async (response) => {
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) => {
18
35
  const headers = new Headers(response.headers);
19
36
  const cookies = response.headers.getSetCookie();
37
+ const cookieDomain = sharedCookieDomain(request, options);
20
38
  if (cookies.length > 0) {
21
39
  headers.delete("set-cookie");
22
40
  for (const cookie of cookies) {
23
- headers.append("set-cookie", hostOnlyCookie(cookie));
41
+ headers.append("set-cookie", cookieForDomain(cookie, cookieDomain));
24
42
  }
25
43
  }
26
44
  return new Response(response.body, {
@@ -46,7 +64,7 @@ const proxyHeaders = (request) => {
46
64
  headers.set("x-forwarded-proto", url.protocol.replace(":", ""));
47
65
  return headers;
48
66
  };
49
- export const proxyAuthRequest = async (request, baseUrl) => {
67
+ export const proxyAuthRequest = async (request, baseUrl, options) => {
50
68
  const target = new URL(request.url);
51
69
  const authUrl = new URL(baseUrl);
52
70
  const init = {
@@ -63,5 +81,5 @@ export const proxyAuthRequest = async (request, baseUrl) => {
63
81
  const response = await fetch(new Request(target, init), {
64
82
  redirect: "manual",
65
83
  });
66
- return proxyResponse(response);
84
+ return proxyResponse(request, response, options);
67
85
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -75,6 +75,7 @@
75
75
  "type:check": "tsc -p tsconfig.json --noEmit"
76
76
  },
77
77
  "dependencies": {
78
+ "@krak-stack/registry": "^0.1.1",
78
79
  "react-qr-code": "^2.2.0"
79
80
  },
80
81
  "peerDependencies": {