@krak-stack/auth 0.1.67 → 0.1.69
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/admin-organization-form.js +1 -1
- package/dist/components/admin-organizations.d.ts +1 -1
- package/dist/components/admin-organizations.js +3 -3
- package/dist/components/admin-users.d.ts +1 -1
- package/dist/components/admin-users.js +3 -3
- package/dist/components/api-key-edit-form.js +1 -1
- package/dist/components/auth-forms.d.ts +7 -0
- package/dist/components/auth-forms.js +18 -8
- package/dist/components/auth-provider.d.ts +1 -0
- package/dist/components/auth-provider.js +20 -1
- package/dist/components/member-required.js +1 -1
- package/dist/components/organization-switcher.js +45 -41
- package/dist/components/user-button.js +4 -4
- package/dist/server/actor.js +16 -2
- package/dist/server/proxy.js +8 -1
- package/package.json +2 -1
|
@@ -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 "
|
|
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 "
|
|
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 "
|
|
9
|
-
import { ErrorMessage } from "
|
|
10
|
-
import { AppBrand } from "
|
|
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 "
|
|
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 "
|
|
9
|
-
import { ErrorMessage } from "
|
|
10
|
-
import { AppBrand } from "
|
|
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 "
|
|
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";
|
|
@@ -5,6 +5,13 @@ type AuthFormProps = {
|
|
|
5
5
|
baseUrl?: string | undefined;
|
|
6
6
|
locale?: KrakstackAuthLocale | undefined;
|
|
7
7
|
};
|
|
8
|
+
type AuthMethod = "password" | "emailOtp";
|
|
9
|
+
export declare const resolveInitialAuthMethod: ({ requestedMethod, lastLoginMethod, emailPassword, emailOtp, }: {
|
|
10
|
+
requestedMethod: string | null;
|
|
11
|
+
lastLoginMethod: string | null | undefined;
|
|
12
|
+
emailPassword: boolean;
|
|
13
|
+
emailOtp: boolean;
|
|
14
|
+
}) => AuthMethod;
|
|
8
15
|
export declare function Signin(props: AuthFormProps): import("react").JSX.Element;
|
|
9
16
|
export declare function VerifyEmail(props: AuthFormProps): import("react").JSX.Element;
|
|
10
17
|
export declare function ForgotPassword(props: AuthFormProps): import("react").JSX.Element;
|
|
@@ -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 "
|
|
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";
|
|
@@ -193,6 +193,17 @@ const authMethodSearch = (searchString, method, email) => {
|
|
|
193
193
|
search.delete("email");
|
|
194
194
|
return Object.fromEntries(search);
|
|
195
195
|
};
|
|
196
|
+
export const resolveInitialAuthMethod = ({ requestedMethod, lastLoginMethod, emailPassword, emailOtp, }) => {
|
|
197
|
+
if (requestedMethod === "password" && emailPassword)
|
|
198
|
+
return "password";
|
|
199
|
+
if (requestedMethod === "emailOtp" && emailOtp)
|
|
200
|
+
return "emailOtp";
|
|
201
|
+
if (lastLoginMethod === "email" && emailPassword)
|
|
202
|
+
return "password";
|
|
203
|
+
if (lastLoginMethod === "email-otp" && emailOtp)
|
|
204
|
+
return "emailOtp";
|
|
205
|
+
return emailOtp ? "emailOtp" : "password";
|
|
206
|
+
};
|
|
196
207
|
export function Signin(props) {
|
|
197
208
|
const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
|
|
198
209
|
const navigate = useNavigate();
|
|
@@ -213,13 +224,12 @@ export function Signin(props) {
|
|
|
213
224
|
google: authOptions?.google ?? true,
|
|
214
225
|
};
|
|
215
226
|
const requestedMethod = getSearchParam(searchString, "method");
|
|
216
|
-
const initialAuthMethod =
|
|
217
|
-
|
|
218
|
-
:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
: "password";
|
|
227
|
+
const [initialAuthMethod] = useState(() => resolveInitialAuthMethod({
|
|
228
|
+
requestedMethod,
|
|
229
|
+
lastLoginMethod: authClient.getLastUsedLoginMethod?.(),
|
|
230
|
+
emailPassword: options.emailPassword,
|
|
231
|
+
emailOtp: options.emailOtp,
|
|
232
|
+
}));
|
|
223
233
|
const initialMethodStep = Boolean(initialEmail) && requestedMethod === initialAuthMethod;
|
|
224
234
|
const [emailSubmitted, setEmailSubmitted] = useState(initialMethodStep);
|
|
225
235
|
const [authMethod, setAuthMethod] = useState(initialAuthMethod);
|
|
@@ -23,6 +23,7 @@ export type KrakstackAuthContextValue = {
|
|
|
23
23
|
authRefreshVersion: number;
|
|
24
24
|
refreshAuth: () => void;
|
|
25
25
|
};
|
|
26
|
+
export declare const listenForSessionRevalidation: (target: EventTarget, revalidate: () => void) => () => void;
|
|
26
27
|
export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, authClient, access, accessLabels, }: KrakstackAuthProviderProps): import("react").JSX.Element;
|
|
27
28
|
export declare const useKrakstackAuth: () => KrakstackAuthContextValue | null;
|
|
28
29
|
export declare const useAuthClient: () => AuthUiClient;
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useAtomSuspense } from "@effect/atom-react";
|
|
3
3
|
import { useRouterState } from "@tanstack/react-router";
|
|
4
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from "react";
|
|
4
|
+
import { createContext, useCallback, useContext, useEffect, useEffectEvent, useMemo, useState, } from "react";
|
|
5
5
|
import { createAuthUiClient } from "./auth-client";
|
|
6
6
|
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
|
+
export const listenForSessionRevalidation = (target, revalidate) => {
|
|
12
|
+
for (const event of sessionRevalidationEvents) {
|
|
13
|
+
target.addEventListener(event, revalidate);
|
|
14
|
+
}
|
|
15
|
+
return () => {
|
|
16
|
+
for (const event of sessionRevalidationEvents) {
|
|
17
|
+
target.removeEventListener(event, revalidate);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
10
21
|
const setProjectContextCookie = (projectId) => {
|
|
11
22
|
if (typeof document === "undefined")
|
|
12
23
|
return;
|
|
@@ -79,9 +90,17 @@ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projec
|
|
|
79
90
|
const refreshAuth = useCallback(() => {
|
|
80
91
|
setAuthRefreshVersion((current) => current + 1);
|
|
81
92
|
}, []);
|
|
93
|
+
const session = resolvedAuthClient.useSession();
|
|
94
|
+
const revalidateSession = useEffectEvent(async () => {
|
|
95
|
+
await session.refetch();
|
|
96
|
+
refreshAuth();
|
|
97
|
+
});
|
|
82
98
|
useEffect(() => {
|
|
83
99
|
setProjectContextCookie(resolvedProjectId);
|
|
84
100
|
}, [resolvedProjectId]);
|
|
101
|
+
useEffect(() => listenForSessionRevalidation(window, () => {
|
|
102
|
+
void revalidateSession();
|
|
103
|
+
}), []);
|
|
85
104
|
const value = useMemo(() => ({
|
|
86
105
|
authClient: resolvedAuthClient,
|
|
87
106
|
baseUrl,
|
|
@@ -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 "
|
|
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 "
|
|
11
|
-
import { ErrorMessage, ImageField, SelectField, SubmitButton, SubmitError, TextAreaField, TextField, } from "
|
|
12
|
-
import { EditingLocaleSwitcher } from "
|
|
13
|
-
import { AppBrand } from "
|
|
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 "
|
|
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";
|
|
@@ -887,6 +887,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
887
887
|
const selectableOrganizations = canSwitchOrganizations
|
|
888
888
|
? visibleOrganizations.filter((organization) => organization.id !== active?.id)
|
|
889
889
|
: [];
|
|
890
|
+
const scrollOrganizationList = selectableOrganizations.length > 5;
|
|
890
891
|
const hasOrganizationListItems = organizations.isPending ||
|
|
891
892
|
Boolean(organizations.error) ||
|
|
892
893
|
canSwitchOrganizations;
|
|
@@ -909,20 +910,23 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
909
910
|
? activeDisplay.name
|
|
910
911
|
: m.organization_switcher_label(), subtitle: activeSubtitle, icon: Building2, variant: "sidebar", className: "min-w-0 flex-1 !p-0 text-left group-data-[collapsible=icon]:flex-none group-data-[collapsible=icon]:justify-start", ...(activeDisplay.image
|
|
911
912
|
? { imageSrc: activeDisplay.image }
|
|
912
|
-
: {}) }), _jsx(ChevronsUpDown, { className: "text-muted-foreground size-4 shrink-0 group-data-[collapsible=icon]:hidden" })] }) }), _jsx(DropdownMenuContent, { className: "min-w-64 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: activeDisplay.name, subtitle: activeSubtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.image
|
|
913
|
+
: {}) }), _jsx(ChevronsUpDown, { className: "text-muted-foreground size-4 shrink-0 group-data-[collapsible=icon]:hidden" })] }) }), _jsx(DropdownMenuContent, { className: "max-w-[calc(100vw-1rem)] min-w-64 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: activeDisplay.name, subtitle: activeSubtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.image
|
|
913
914
|
? { imageSrc: activeDisplay.image }
|
|
914
|
-
: {}) }) }), menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizations.error ? (_jsx(DropdownMenuItem, { disabled: true, children: organizations.error.message })) : null, canSwitchOrganizations && selectableOrganizations.length ? (
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
915
|
+
: {}) }) }), menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizations.error ? (_jsx(DropdownMenuItem, { disabled: true, children: organizations.error.message })) : null, canSwitchOrganizations && selectableOrganizations.length ? (_jsx("div", { className: cn(scrollOrganizationList &&
|
|
916
|
+
"max-h-64 overflow-y-auto overscroll-contain"), children: selectableOrganizations.map((organization) => {
|
|
917
|
+
const display = organizationDisplay(organization, m, baseUrl);
|
|
918
|
+
return (_jsx(DropdownMenuItem, { onClick: async () => {
|
|
919
|
+
const result = await authClient.organization.setActive({
|
|
920
|
+
organizationId: organization.id,
|
|
921
|
+
});
|
|
922
|
+
if (!result.error) {
|
|
923
|
+
await refresh();
|
|
924
|
+
onChange?.(organization);
|
|
925
|
+
}
|
|
926
|
+
}, children: _jsx(AppBrand, { to: null, label: display.name, subtitle: organizationSwitcherSubtitle(organization, display.subtitle, m), icon: Building2, className: "w-full text-left [&>div:first-child]:size-7", ...(display.image
|
|
927
|
+
? { imageSrc: display.image }
|
|
928
|
+
: {}) }) }, organization.id));
|
|
929
|
+
}) })) : canSwitchOrganizations && !organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: active
|
|
926
930
|
? m.organization_switcher_no_other_organizations()
|
|
927
931
|
: m.organization_switcher_empty() })) : null, canCreateOrganization || canViewOrganizationInvitations ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), canCreateOrganization ? (_jsxs(DropdownMenuItem, { onClick: openCreate, children: [_jsx(Plus, {}), m.organization_create_title()] })) : null, canViewOrganizationInvitations ? (_jsxs(DropdownMenuItem, { onClick: () => {
|
|
928
932
|
setDialog("invitations");
|
|
@@ -958,7 +962,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
958
962
|
auth?.access?.apiKeyPermissions.organization ??
|
|
959
963
|
{} })) : null }) }), _jsx(Dialog, { open: dialog === "invitations" && canViewOrganizationInvitations, onOpenChange: (open) => {
|
|
960
964
|
setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
|
|
961
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, baseUrl: baseUrl, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization.data
|
|
965
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, baseUrl: baseUrl, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization.data
|
|
962
966
|
? { activeOrganizationId: activeOrganization.data.id }
|
|
963
967
|
: {}), onActionComplete: refreshAfterInvitationAction })] }) })] }));
|
|
964
968
|
}
|
|
@@ -995,28 +999,28 @@ function UserInvitationsManager({ authClient, baseUrl, invitations, loading, err
|
|
|
995
999
|
}
|
|
996
1000
|
await onActionComplete(activeOrganizationId);
|
|
997
1001
|
};
|
|
998
|
-
return (_jsxs("section", { className: "flex flex-col gap-4", children: [error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, actionError ? (_jsx("p", { className: "text-destructive text-sm", children: actionError })) : null, _jsx(DataTable, { columns: userInvitationColumns({
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1002
|
+
return (_jsxs("section", { className: "flex min-w-0 flex-col gap-4", children: [error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, actionError ? (_jsx("p", { className: "text-destructive text-sm", children: actionError })) : null, _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: userInvitationColumns({
|
|
1003
|
+
baseUrl,
|
|
1004
|
+
m,
|
|
1005
|
+
now: invitationNow,
|
|
1006
|
+
}), data: invitations, features: {
|
|
1007
|
+
export: { baseName: "organization-invitations" },
|
|
1008
|
+
gallery: false,
|
|
1009
|
+
rowActions: {
|
|
1010
|
+
items: userInvitationRowActions({
|
|
1011
|
+
m,
|
|
1012
|
+
actingInvitationId,
|
|
1013
|
+
now: invitationNow,
|
|
1014
|
+
onAccept: acceptInvitation,
|
|
1015
|
+
onReject: rejectInvitation,
|
|
1016
|
+
}),
|
|
1017
|
+
},
|
|
1018
|
+
}, searchState: "local", state: {
|
|
1019
|
+
empty: loading
|
|
1020
|
+
? m.user_loading()
|
|
1021
|
+
: m.organization_user_invitations_empty(),
|
|
1022
|
+
loading,
|
|
1023
|
+
} }) })] }));
|
|
1020
1024
|
}
|
|
1021
1025
|
const userInvitationColumns = ({ baseUrl, m, now, }) => [
|
|
1022
1026
|
{
|
|
@@ -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 "
|
|
12
|
-
import { AppBrand } from "
|
|
13
|
-
import { effectFormMessages, ImageField, SubmitButton, SubmitError, TextAreaField, TextField, } from "
|
|
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 "
|
|
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";
|
package/dist/server/actor.js
CHANGED
|
@@ -90,6 +90,20 @@ const matchesConstraint = (actor, constraint) => {
|
|
|
90
90
|
const requiredActor = (access, constraint) => resolveCurrentActor(access).pipe(Effect.flatMap((actor) => matchesConstraint(actor, constraint)
|
|
91
91
|
? Effect.succeed(actor)
|
|
92
92
|
: Effect.fail(new HttpApiError.Forbidden({}))));
|
|
93
|
+
const withCurrentActor = (httpEffect, actor) => {
|
|
94
|
+
const userId = actor.actor.type === "user"
|
|
95
|
+
? actor.actor.userId
|
|
96
|
+
: actor.actor.owner.type === "user"
|
|
97
|
+
? actor.actor.owner.userId
|
|
98
|
+
: undefined;
|
|
99
|
+
const attributes = {
|
|
100
|
+
...(actor.organizationId
|
|
101
|
+
? { "organization.id": actor.organizationId }
|
|
102
|
+
: {}),
|
|
103
|
+
...(userId ? { "user.id": userId } : {}),
|
|
104
|
+
};
|
|
105
|
+
return Effect.annotateCurrentSpan(attributes).pipe(Effect.andThen(httpEffect.pipe(Effect.provideService(CurrentActor, actor), Effect.annotateSpans(attributes), Effect.annotateLogs(attributes))));
|
|
106
|
+
};
|
|
93
107
|
const actorRequired = (constraint) => {
|
|
94
108
|
if (!constraint)
|
|
95
109
|
return AnyActorRequired;
|
|
@@ -102,10 +116,10 @@ const actorRequired = (constraint) => {
|
|
|
102
116
|
}
|
|
103
117
|
return ApiKeyActorRequired;
|
|
104
118
|
};
|
|
105
|
-
const actorRequiredLayer = (access) => Layer.mergeAll(Layer.succeed(AnyActorRequired, (httpEffect) => requiredActor(access).pipe(Effect.flatMap((actor) => httpEffect
|
|
119
|
+
const actorRequiredLayer = (access) => Layer.mergeAll(Layer.succeed(AnyActorRequired, (httpEffect) => requiredActor(access).pipe(Effect.flatMap((actor) => withCurrentActor(httpEffect, actor)))), Layer.succeed(UserActorRequired, (httpEffect) => requiredActor(access, { type: "user" }).pipe(Effect.flatMap((actor) => withCurrentActor(httpEffect, actor)))), Layer.succeed(ApiKeyActorRequired, (httpEffect) => requiredActor(access, { type: "apiKey" }).pipe(Effect.flatMap((actor) => withCurrentActor(httpEffect, actor)))), Layer.succeed(UserApiKeyActorRequired, (httpEffect) => requiredActor(access, { type: "apiKey", ownerType: "user" }).pipe(Effect.flatMap((actor) => withCurrentActor(httpEffect, actor)))), Layer.succeed(OrganizationApiKeyActorRequired, (httpEffect) => requiredActor(access, {
|
|
106
120
|
type: "apiKey",
|
|
107
121
|
ownerType: "organization",
|
|
108
|
-
}).pipe(Effect.flatMap((actor) => httpEffect
|
|
122
|
+
}).pipe(Effect.flatMap((actor) => withCurrentActor(httpEffect, actor)))));
|
|
109
123
|
export const ActorRequired = Object.assign(actorRequired, {
|
|
110
124
|
layer: actorRequiredLayer,
|
|
111
125
|
});
|
package/dist/server/proxy.js
CHANGED
|
@@ -12,9 +12,14 @@ const blockedRequestHeaders = [
|
|
|
12
12
|
"transfer-encoding",
|
|
13
13
|
"upgrade",
|
|
14
14
|
"cdn-loop",
|
|
15
|
+
"x-krakstack-forwarded-host",
|
|
16
|
+
"x-krakstack-forwarded-proto",
|
|
15
17
|
];
|
|
16
18
|
const hostOnlyCookie = (cookie) => cookie.replace(/;\s*domain=[^;]*/gi, "");
|
|
17
|
-
const normalizedCookieDomain = (domain) => domain
|
|
19
|
+
const normalizedCookieDomain = (domain) => domain
|
|
20
|
+
.trim()
|
|
21
|
+
.toLowerCase()
|
|
22
|
+
.replace(/^\.+|\.+$/g, "");
|
|
18
23
|
const sharedCookieDomain = (request, options) => {
|
|
19
24
|
if (!options?.cookieDomain)
|
|
20
25
|
return null;
|
|
@@ -62,6 +67,8 @@ const proxyHeaders = (request) => {
|
|
|
62
67
|
}
|
|
63
68
|
headers.set("x-forwarded-host", url.host);
|
|
64
69
|
headers.set("x-forwarded-proto", url.protocol.replace(":", ""));
|
|
70
|
+
headers.set("x-krakstack-forwarded-host", url.host);
|
|
71
|
+
headers.set("x-krakstack-forwarded-proto", url.protocol.replace(":", ""));
|
|
65
72
|
return headers;
|
|
66
73
|
};
|
|
67
74
|
export const proxyAuthRequest = async (request, baseUrl, options) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.69",
|
|
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.6",
|
|
78
79
|
"react-qr-code": "^2.2.0"
|
|
79
80
|
},
|
|
80
81
|
"peerDependencies": {
|