@krak-stack/auth 0.2.20 → 0.2.22
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/CHANGELOG.md +15 -0
- package/dist/components/admin-organization-form.js +2 -2
- package/dist/components/admin-organizations.js +6 -20
- package/dist/components/admin-users.js +2 -14
- package/dist/components/auth-atoms.d.ts +1 -0
- package/dist/components/auth-atoms.js +5 -0
- package/dist/components/organization-switcher.js +16 -16
- package/dist/components/user-button.js +2 -2
- package/package.json +5 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @krak-stack/auth
|
|
2
|
+
|
|
3
|
+
## 0.2.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Update the KrakStack registry development dependency and minimum peer requirement to `0.1.48` for corrected image previews, full-width image inputs, file metadata, and non-overlapping replace/delete actions. Use compact, consistently sized icon and logo previews in account and organization forms without changing suggested upload resolutions.
|
|
8
|
+
|
|
9
|
+
## 0.2.21
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Reload the current page after impersonation instead of navigating to `/` or refreshing the previous user's mounted guards. This clears stale router and organization query state when switching identities while preserving the current URL.
|
|
14
|
+
|
|
15
|
+
Update the SDK's KrakStack registry development dependency and minimum peer requirement to `0.1.44`.
|
|
@@ -149,8 +149,8 @@ export function AdminOrganizationForm({ organization, onClose, onSaved, }) {
|
|
|
149
149
|
logo: assetUrl(organization?.logo, baseUrl),
|
|
150
150
|
parentId: organization?.parentId ?? noParentOrganization,
|
|
151
151
|
}, children: _jsxs("div", { className: "flex flex-col gap-4", children: [_jsx(form.name, { autoFocus: true, label: m.field_name }), _jsx(form.slug, { description: m.organization_slug_description, label: m.organization_slug }), _jsx(form.logo, { label: m.organization_field_logo_url, size: {
|
|
152
|
-
width:
|
|
153
|
-
height:
|
|
152
|
+
width: 140,
|
|
153
|
+
height: 40,
|
|
154
154
|
suggestedWidth: 512,
|
|
155
155
|
suggestedHeight: 512,
|
|
156
156
|
} }), _jsx(form.parentId, { description: m.organization_parent_description, emptyLabel: m.organization_parent_empty, items: parentOptions, label: m.organization_parent, placeholder: m.organization_parent_none }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form, children: m.form_submit })] }) })] }) }));
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useAtomSet, useAtomSubscribe, useAtomValue } from "@effect/atom-react";
|
|
3
|
-
import { useNavigate, useRouter } from "@tanstack/react-router";
|
|
4
3
|
import { Cause, Effect, Schema } from "effect";
|
|
5
4
|
import { Atom, AsyncResult } from "effect/reactivity";
|
|
6
5
|
import { Building2, Pencil, Trash2, UserCog } from "lucide-react";
|
|
@@ -17,7 +16,7 @@ import { AdminOrganizationForm } from "./admin-organization-form.js";
|
|
|
17
16
|
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
18
17
|
import { useKrakstackAuth } from "./auth-provider.js";
|
|
19
18
|
import { assetUrl, organizationBranding } from "./utils.js";
|
|
20
|
-
import { authSessionAtom, notifyAuthChange } from "./auth-atoms.js";
|
|
19
|
+
import { authSessionAtom, notifyAuthChange, reloadAfterImpersonation, } from "./auth-atoms.js";
|
|
21
20
|
const defaultMessages = {
|
|
22
21
|
en: {
|
|
23
22
|
admin_column_created: "Created",
|
|
@@ -132,8 +131,6 @@ export function AdminOrganizationsTable({ messages: messageOverrides, onSearchCh
|
|
|
132
131
|
const m = adminOrganizationsMessages(locale, messageOverrides);
|
|
133
132
|
const baseUrl = auth?.baseUrl;
|
|
134
133
|
const projectId = auth?.projectId;
|
|
135
|
-
const navigate = useNavigate();
|
|
136
|
-
const router = useRouter();
|
|
137
134
|
const sessionResult = useAtomValue(authSessionAtom(baseUrl));
|
|
138
135
|
const actorUserId = AsyncResult.match(sessionResult, {
|
|
139
136
|
onInitial: () => null,
|
|
@@ -145,14 +142,10 @@ export function AdminOrganizationsTable({ messages: messageOverrides, onSearchCh
|
|
|
145
142
|
yield* client.auth.adminImpersonateUser({ payload: { userId } });
|
|
146
143
|
yield* client.auth
|
|
147
144
|
.organizationSetActive({ payload: { organizationId } })
|
|
148
|
-
.pipe(Effect.tapError(() => client.auth
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
await router.invalidate();
|
|
153
|
-
},
|
|
154
|
-
catch: (cause) => cause instanceof Error ? cause : new Error(String(cause)),
|
|
155
|
-
});
|
|
145
|
+
.pipe(Effect.tapError(() => client.auth
|
|
146
|
+
.adminStopImpersonating({ payload: {} })
|
|
147
|
+
.pipe(Effect.tap(() => Effect.sync(notifyAuthChange)))));
|
|
148
|
+
yield* Effect.sync(reloadAfterImpersonation);
|
|
156
149
|
})));
|
|
157
150
|
const impersonate = useAtomSet(impersonateAtom);
|
|
158
151
|
const impersonateResult = useAtomValue(impersonateAtom);
|
|
@@ -161,14 +154,7 @@ export function AdminOrganizationsTable({ messages: messageOverrides, onSearchCh
|
|
|
161
154
|
yield* client.auth.organizationImpersonateUser({
|
|
162
155
|
payload: { actorUserId, organizationId, targetUserId },
|
|
163
156
|
});
|
|
164
|
-
|
|
165
|
-
yield* Effect.tryPromise({
|
|
166
|
-
try: async () => {
|
|
167
|
-
await navigate({ to: "/" });
|
|
168
|
-
await router.invalidate();
|
|
169
|
-
},
|
|
170
|
-
catch: (cause) => cause instanceof Error ? cause : new Error(String(cause)),
|
|
171
|
-
});
|
|
157
|
+
yield* Effect.sync(reloadAfterImpersonation);
|
|
172
158
|
})));
|
|
173
159
|
const impersonateAsOrganization = useAtomSet(impersonateAsOrganizationAtom);
|
|
174
160
|
const impersonateAsOrganizationResult = useAtomValue(impersonateAsOrganizationAtom);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
|
-
import { useNavigate, useRouter } from "@tanstack/react-router";
|
|
4
3
|
import { Atom, AsyncResult } from "effect/reactivity";
|
|
5
4
|
import { Effect, Schema } from "effect";
|
|
6
5
|
import { Ban, Loader2, ShieldOff, UserCog, UserIcon } from "lucide-react";
|
|
@@ -12,7 +11,7 @@ import { AppBrand } from "@krak-stack/registry/app-brand";
|
|
|
12
11
|
import { Badge } from "@/components/ui/badge";
|
|
13
12
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
|
|
14
13
|
import { AdminListQuery } from "../admin/schema.js";
|
|
15
|
-
import {
|
|
14
|
+
import { reloadAfterImpersonation } from "./auth-atoms.js";
|
|
16
15
|
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
17
16
|
import { useKrakstackAuth } from "./auth-provider.js";
|
|
18
17
|
import { assetUrl } from "./utils.js";
|
|
@@ -109,8 +108,6 @@ const makeAdminUsersTableAtoms = (initial) => {
|
|
|
109
108
|
return { requestAtom, resultAtom };
|
|
110
109
|
};
|
|
111
110
|
export function AdminUsersTable({ onSearchChange, reloadKey = 0, search, }) {
|
|
112
|
-
const navigate = useNavigate();
|
|
113
|
-
const router = useRouter();
|
|
114
111
|
const auth = useKrakstackAuth();
|
|
115
112
|
const m = labels(auth?.locale ?? "en");
|
|
116
113
|
const baseUrl = auth?.baseUrl;
|
|
@@ -140,16 +137,7 @@ export function AdminUsersTable({ onSearchChange, reloadKey = 0, search, }) {
|
|
|
140
137
|
const [impersonateUserAtom] = useState(() => authClientApi(baseUrl).runtime.fn((userId) => Effect.gen(function* () {
|
|
141
138
|
const client = yield* authHttpClient(baseUrl);
|
|
142
139
|
yield* client.auth.adminImpersonateUser({ payload: { userId } });
|
|
143
|
-
|
|
144
|
-
yield* Effect.tryPromise({
|
|
145
|
-
try: async () => {
|
|
146
|
-
await navigate({ to: "/" });
|
|
147
|
-
await router.invalidate();
|
|
148
|
-
},
|
|
149
|
-
catch: (cause) => cause instanceof Error
|
|
150
|
-
? cause
|
|
151
|
-
: new Error(m.admin_error_impersonate),
|
|
152
|
-
});
|
|
140
|
+
yield* Effect.sync(reloadAfterImpersonation);
|
|
153
141
|
}).pipe(Effect.catch((cause) => Effect.sync(() => setImpersonateError(cause instanceof Error
|
|
154
142
|
? cause.message
|
|
155
143
|
: m.admin_error_impersonate))))));
|
|
@@ -146,3 +146,4 @@ export declare const activeAuthOrganizationAtom: (arg: string | undefined) => (a
|
|
|
146
146
|
} | null, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized>>;
|
|
147
147
|
export declare const getLastUsedLoginMethod: () => string | null;
|
|
148
148
|
export declare const notifyAuthChange: () => void;
|
|
149
|
+
export declare const reloadAfterImpersonation: () => void;
|
|
@@ -59,3 +59,8 @@ export const getLastUsedLoginMethod = () => {
|
|
|
59
59
|
export const notifyAuthChange = () => {
|
|
60
60
|
globalThis.window?.dispatchEvent(new Event(AUTH_CLIENT_CHANGE_EVENT));
|
|
61
61
|
};
|
|
62
|
+
// Changing identity must discard the host application's router and query caches.
|
|
63
|
+
// Do not notify mounted guards first: they still belong to the previous user.
|
|
64
|
+
export const reloadAfterImpersonation = () => {
|
|
65
|
+
window.location.reload();
|
|
66
|
+
};
|
|
@@ -1030,23 +1030,23 @@ function EditOrganizationSection({ header, baseUrl, editingLocale, organization,
|
|
|
1030
1030
|
event.stopPropagation();
|
|
1031
1031
|
submit();
|
|
1032
1032
|
}, children: _jsxs(ScrollableDialogContent, { size: "2xl", children: [_jsx(ScrollableDialogHeader, { children: header }), _jsxs(ScrollableDialogBody, { className: "flex flex-col gap-4", padding: "form", children: [_jsxs(OrganizationFormSection, { title: m.organization_profile(), description: m.organization_translation_description(), children: [_jsxs(FieldSet, { disabled: editingLocale !== "en", className: editingLocale === "en" ? "contents" : "hidden", children: [_jsx(form.enName, { label: m.organization_translation_name() }), _jsx(form.enLogo, { label: m.organization_logo(), size: {
|
|
1033
|
-
width:
|
|
1034
|
-
height:
|
|
1033
|
+
width: 140,
|
|
1034
|
+
height: 40,
|
|
1035
1035
|
suggestedWidth: 350,
|
|
1036
1036
|
suggestedHeight: 100,
|
|
1037
1037
|
} }), _jsx(form.enIcon, { label: m.organization_icon(), size: {
|
|
1038
|
-
width:
|
|
1039
|
-
height:
|
|
1038
|
+
width: 40,
|
|
1039
|
+
height: 40,
|
|
1040
1040
|
suggestedWidth: 512,
|
|
1041
1041
|
suggestedHeight: 512,
|
|
1042
1042
|
} })] }), _jsxs(FieldSet, { disabled: editingLocale !== "fr", className: editingLocale === "fr" ? "contents" : "hidden", children: [_jsx(form.frName, { label: m.organization_translation_name() }), _jsx(form.frLogo, { label: m.organization_logo(), size: {
|
|
1043
|
-
width:
|
|
1044
|
-
height:
|
|
1043
|
+
width: 140,
|
|
1044
|
+
height: 40,
|
|
1045
1045
|
suggestedWidth: 350,
|
|
1046
1046
|
suggestedHeight: 100,
|
|
1047
1047
|
} }), _jsx(form.frIcon, { label: m.organization_icon(), size: {
|
|
1048
|
-
width:
|
|
1049
|
-
height:
|
|
1048
|
+
width: 40,
|
|
1049
|
+
height: 40,
|
|
1050
1050
|
suggestedWidth: 512,
|
|
1051
1051
|
suggestedHeight: 512,
|
|
1052
1052
|
} })] })] }), _jsx(Separator, { className: "my-2" }), _jsx(form.slug, { label: m.organization_slug(), description: m.organization_slug_identifier_description(), required: true }), _jsx(Separator, { className: "my-2" }), _jsxs(OrganizationFormSection, { title: m.organization_contact(), children: [_jsx(OrganizationContactGroup, { title: m.organization_contact_email_type(), children: _jsx(form.emails, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) })] }), _jsx(Separator, { className: "my-2" }), _jsx(OrganizationFormSection, { title: m.organization_address(), children: _jsx(form.addresses, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) })] }), _jsx(DialogFooter, { className: "-mx-6 -mb-6 border-t px-6 py-4", children: _jsxs("div", { className: "flex flex-col gap-3", children: [_jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) })] }) }) }));
|
|
@@ -1106,23 +1106,23 @@ function CreateOrganizationSection({ header, baseUrl, editingLocale, onCreated,
|
|
|
1106
1106
|
event.stopPropagation();
|
|
1107
1107
|
submit();
|
|
1108
1108
|
}, children: _jsxs(ScrollableDialogContent, { size: "2xl", children: [_jsx(ScrollableDialogHeader, { children: header }), _jsxs(ScrollableDialogBody, { className: "flex flex-col gap-4", padding: "form", children: [_jsxs(OrganizationFormSection, { title: m.organization_profile(), description: m.organization_translation_description(), children: [_jsxs(FieldSet, { disabled: editingLocale !== "en", className: editingLocale === "en" ? "contents" : "hidden", children: [_jsx(form.enName, { label: m.organization_translation_name() }), _jsx(form.enLogo, { label: m.organization_logo(), size: {
|
|
1109
|
-
width:
|
|
1110
|
-
height:
|
|
1109
|
+
width: 140,
|
|
1110
|
+
height: 40,
|
|
1111
1111
|
suggestedWidth: 350,
|
|
1112
1112
|
suggestedHeight: 100,
|
|
1113
1113
|
} }), _jsx(form.enIcon, { label: m.organization_icon(), size: {
|
|
1114
|
-
width:
|
|
1115
|
-
height:
|
|
1114
|
+
width: 40,
|
|
1115
|
+
height: 40,
|
|
1116
1116
|
suggestedWidth: 512,
|
|
1117
1117
|
suggestedHeight: 512,
|
|
1118
1118
|
} })] }), _jsxs(FieldSet, { disabled: editingLocale !== "fr", className: editingLocale === "fr" ? "contents" : "hidden", children: [_jsx(form.frName, { label: m.organization_translation_name() }), _jsx(form.frLogo, { label: m.organization_logo(), size: {
|
|
1119
|
-
width:
|
|
1120
|
-
height:
|
|
1119
|
+
width: 140,
|
|
1120
|
+
height: 40,
|
|
1121
1121
|
suggestedWidth: 350,
|
|
1122
1122
|
suggestedHeight: 100,
|
|
1123
1123
|
} }), _jsx(form.frIcon, { label: m.organization_icon(), size: {
|
|
1124
|
-
width:
|
|
1125
|
-
height:
|
|
1124
|
+
width: 40,
|
|
1125
|
+
height: 40,
|
|
1126
1126
|
suggestedWidth: 512,
|
|
1127
1127
|
suggestedHeight: 512,
|
|
1128
1128
|
} })] })] }), _jsx(Separator, { className: "my-2" }), _jsx(form.slug, { label: m.organization_slug(), description: `${m.organization_slug_identifier_description()} ${m.organization_slug_description()}` }), _jsx(Separator, { className: "my-2" }), _jsxs(OrganizationFormSection, { title: m.organization_contact(), children: [_jsx(OrganizationContactGroup, { title: m.organization_contact_email_type(), children: _jsx(form.emails, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) })] }), _jsx(Separator, { className: "my-2" }), _jsx(OrganizationFormSection, { title: m.organization_address(), children: _jsx(form.addresses, { locale: editingLocale, messages: organizationContactFieldMessages(m) }) })] }), _jsx(DialogFooter, { className: "-mx-6 -mb-6 border-t px-6 py-4", children: _jsxs("div", { className: "flex flex-col gap-3", children: [_jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) })] }) }) }));
|
|
@@ -826,8 +826,8 @@ const UserForm = ({ defaultValues, error, onSubmit, }) => {
|
|
|
826
826
|
event.stopPropagation();
|
|
827
827
|
submit();
|
|
828
828
|
}, children: _jsxs(ScrollableDialogContent, { size: "3xl", children: [_jsx(ScrollableDialogHeader, { children: _jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_form_title() }), _jsx(DialogDescription, { children: m.user_form_description() })] }) }), _jsxs(ScrollableDialogBody, { className: "flex flex-col gap-4", padding: "form", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_profile_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_profile_description() })] }), _jsx(form.image, { label: m.user_profile_photo_upload_label(), size: {
|
|
829
|
-
width:
|
|
830
|
-
height:
|
|
829
|
+
width: 40,
|
|
830
|
+
height: 40,
|
|
831
831
|
suggestedWidth: 512,
|
|
832
832
|
suggestedHeight: 512,
|
|
833
833
|
} }), _jsx(form.name, { label: m.user_form_name_label(), autoComplete: "name", required: true }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h3", { className: "text-sm leading-none font-medium", children: m.user_contact_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_contact_description() })] }), _jsx(EditingLocaleSwitcher, { locale: auth?.locale, value: editingLocale, onValueChange: (value) => setEditingLocale(value === "fr" ? "fr" : "en") })] }), _jsx(UserContactGroup, { title: m.user_contact_email_type(), children: _jsx(form.emails, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) })] })] }), _jsx(DialogFooter, { className: "-mx-6 -mb-6 border-t px-6 py-4", children: _jsxs("div", { className: "flex flex-col gap-3", children: [error && (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: error })), _jsx(SubmitButton, { form: form })] }) })] }) }) }));
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/auth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.22",
|
|
4
4
|
"description": "Effect HttpApi clients and schemas for KrakStack Auth.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
8
|
-
"tailwind.css"
|
|
8
|
+
"tailwind.css",
|
|
9
|
+
"CHANGELOG.md"
|
|
9
10
|
],
|
|
10
11
|
"type": "module",
|
|
11
12
|
"sideEffects": false,
|
|
@@ -75,10 +76,10 @@
|
|
|
75
76
|
"react-qr-code": "^2.2.0"
|
|
76
77
|
},
|
|
77
78
|
"devDependencies": {
|
|
78
|
-
"@krak-stack/registry": "0.1.
|
|
79
|
+
"@krak-stack/registry": "0.1.48"
|
|
79
80
|
},
|
|
80
81
|
"peerDependencies": {
|
|
81
|
-
"@krak-stack/registry": "^0.1.
|
|
82
|
+
"@krak-stack/registry": "^0.1.48",
|
|
82
83
|
"@tanstack/react-router": "^1.170.15",
|
|
83
84
|
"effect": "^4.0.0",
|
|
84
85
|
"input-otp": "^1.5.0",
|