@krak-stack/auth 0.2.20 → 0.2.21
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
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @krak-stack/auth
|
|
2
|
+
|
|
3
|
+
## 0.2.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 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.
|
|
8
|
+
|
|
9
|
+
Update the SDK's KrakStack registry development dependency and minimum peer requirement to `0.1.44`.
|
|
@@ -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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/auth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.21",
|
|
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.44"
|
|
79
80
|
},
|
|
80
81
|
"peerDependencies": {
|
|
81
|
-
"@krak-stack/registry": "^0.1.
|
|
82
|
+
"@krak-stack/registry": "^0.1.44",
|
|
82
83
|
"@tanstack/react-router": "^1.170.15",
|
|
83
84
|
"effect": "^4.0.0",
|
|
84
85
|
"input-otp": "^1.5.0",
|