@krak-stack/auth 0.1.20 → 0.1.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/dist/components/index.d.ts +2 -0
- package/dist/components/organization-switcher.d.ts +4 -1
- package/dist/components/organization-switcher.js +11 -2
- package/dist/components/user-button.d.ts +4 -1
- package/dist/components/user-button.js +11 -2
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { OrganizationSwitcher } from "./organization-switcher";
|
|
2
2
|
export { UserButton } from "./user-button";
|
|
3
|
+
export type { OrganizationSwitcherDialog } from "./organization-switcher";
|
|
4
|
+
export type { UserButtonDialog } from "./user-button";
|
|
3
5
|
export type { AuthUiClient } from "./auth-client";
|
|
@@ -169,8 +169,10 @@ type OrganizationSwitcherProps = {
|
|
|
169
169
|
renderUnauthenticated?: () => ReactNode;
|
|
170
170
|
locked?: boolean;
|
|
171
171
|
messages?: OrganizationSwitcherMessages;
|
|
172
|
+
dialog?: OrganizationSwitcherDialog | null;
|
|
172
173
|
onChange?: (organization: OrganizationSummary | null) => void;
|
|
173
174
|
onCreate?: (organization: OrganizationSummary) => void;
|
|
175
|
+
onDialogChange?: (dialog: OrganizationSwitcherDialog | null) => void;
|
|
174
176
|
};
|
|
175
177
|
type OrganizationSummary = {
|
|
176
178
|
id: string;
|
|
@@ -178,5 +180,6 @@ type OrganizationSummary = {
|
|
|
178
180
|
slug: string;
|
|
179
181
|
metadata?: unknown;
|
|
180
182
|
};
|
|
181
|
-
export
|
|
183
|
+
export type OrganizationSwitcherDialog = "create" | "manage" | "members" | "apiKeys" | "invitations";
|
|
184
|
+
export declare function OrganizationSwitcher({ authClient, baseUrl, side, className, renderUnauthenticated, locked, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }: OrganizationSwitcherProps): import("react").JSX.Element;
|
|
182
185
|
export {};
|
|
@@ -342,13 +342,14 @@ const organizationMetadataFromForm = async (authClient, value, m) => {
|
|
|
342
342
|
}
|
|
343
343
|
return { translations };
|
|
344
344
|
};
|
|
345
|
-
export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", className, renderUnauthenticated, locked = false, messages, onChange, onCreate, }) {
|
|
345
|
+
export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", className, renderUnauthenticated, locked = false, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
|
|
346
346
|
const labels = organizationSwitcherMessages(messages);
|
|
347
347
|
const m = organizationMessageFns(labels);
|
|
348
348
|
const session = authClient.useSession();
|
|
349
349
|
const organizations = authClient.useListOrganizations();
|
|
350
350
|
const activeOrganization = authClient.useActiveOrganization();
|
|
351
|
-
const [
|
|
351
|
+
const [uncontrolledDialog, setUncontrolledDialog] = useState(null);
|
|
352
|
+
const dialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
|
|
352
353
|
const sessionUserId = session.data?.user.id;
|
|
353
354
|
const [userInvitations, setUserInvitations] = useState([]);
|
|
354
355
|
const [userInvitationsError, setUserInvitationsError] = useState(null);
|
|
@@ -367,6 +368,14 @@ export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", cla
|
|
|
367
368
|
setUserInvitations(result.data ?? []);
|
|
368
369
|
setLoadingUserInvitations(false);
|
|
369
370
|
});
|
|
371
|
+
const setDialog = (next) => {
|
|
372
|
+
const nextDialog = typeof next === "function" ? next(dialog) : next;
|
|
373
|
+
if (nextDialog === dialog)
|
|
374
|
+
return;
|
|
375
|
+
if (controlledDialog === undefined)
|
|
376
|
+
setUncontrolledDialog(nextDialog);
|
|
377
|
+
onDialogChange?.(nextDialog);
|
|
378
|
+
};
|
|
370
379
|
useEffect(() => {
|
|
371
380
|
if (!sessionUserId)
|
|
372
381
|
return;
|
|
@@ -175,6 +175,9 @@ type UserDropdownProps = {
|
|
|
175
175
|
renderUnauthenticated?: () => ReactNode;
|
|
176
176
|
apiKeyPermissions?: Record<string, string[]>;
|
|
177
177
|
messages?: UserButtonMessages;
|
|
178
|
+
dialog?: UserButtonDialog | null;
|
|
179
|
+
onDialogChange?: (dialog: UserButtonDialog | null) => void;
|
|
178
180
|
};
|
|
179
|
-
export
|
|
181
|
+
export type UserButtonDialog = "account" | "security" | "apiKeys";
|
|
182
|
+
export declare const UserButton: ({ authClient, baseUrl, signOutRedirect, side, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }: UserDropdownProps) => import("react").JSX.Element;
|
|
180
183
|
export {};
|
|
@@ -218,7 +218,7 @@ const presignUserImageUpload = async (authClient, file, m) => {
|
|
|
218
218
|
}
|
|
219
219
|
return { uploadUrl, url };
|
|
220
220
|
};
|
|
221
|
-
export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side = "bottom", renderUnauthenticated, apiKeyPermissions, messages, }) => {
|
|
221
|
+
export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side = "bottom", renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
|
|
222
222
|
const labels = userButtonMessages(messages);
|
|
223
223
|
const m = userButtonMessageFns(labels);
|
|
224
224
|
const navigate = useNavigate();
|
|
@@ -226,8 +226,17 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
|
|
|
226
226
|
select: (state) => `${import.meta.env.VITE_SITE_URL}${state.location.href}`,
|
|
227
227
|
});
|
|
228
228
|
const { data: session, isPending, refetch } = authClient.useSession();
|
|
229
|
-
const [
|
|
229
|
+
const [uncontrolledDialog, setUncontrolledDialog] = useState(null);
|
|
230
|
+
const settingsDialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
|
|
230
231
|
const [formError, setFormError] = useState(null);
|
|
232
|
+
const setSettingsDialog = (next) => {
|
|
233
|
+
const nextDialog = typeof next === "function" ? next(settingsDialog) : next;
|
|
234
|
+
if (nextDialog === settingsDialog)
|
|
235
|
+
return;
|
|
236
|
+
if (controlledDialog === undefined)
|
|
237
|
+
setUncontrolledDialog(nextDialog);
|
|
238
|
+
onDialogChange?.(nextDialog);
|
|
239
|
+
};
|
|
231
240
|
if (!session) {
|
|
232
241
|
return _jsx(_Fragment, { children: renderUnauthenticated?.() });
|
|
233
242
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./schema";
|
|
2
2
|
export { AuthApiClients, AuthClient, type AuthClientLayerOptions, } from "./client";
|
|
3
3
|
export { AuthClientConfig } from "./config";
|
|
4
|
-
export { OrganizationSwitcher, UserButton, type AuthUiClient, } from "./components";
|
|
4
|
+
export { OrganizationSwitcher, UserButton, type AuthUiClient, type OrganizationSwitcherDialog, type UserButtonDialog, } from "./components";
|
|
5
5
|
export * as BetterAuth from "./better-auth";
|
|
6
6
|
export * as Extra from "./extra";
|
|
7
7
|
export * as Server from "./server";
|