@krak-stack/auth 0.1.19 → 0.1.20
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/organization-switcher.d.ts +2 -1
- package/dist/components/organization-switcher.js +17 -17
- package/dist/components/user-button.d.ts +2 -1
- package/dist/components/user-button.js +3 -3
- package/dist/components/utils.d.ts +1 -0
- package/dist/components/utils.js +10 -0
- package/package.json +1 -1
|
@@ -163,6 +163,7 @@ type OrganizationSwitcherMessageKey = keyof (typeof messages)["en"];
|
|
|
163
163
|
export type OrganizationSwitcherMessages = Partial<Record<OrganizationSwitcherMessageKey, string>>;
|
|
164
164
|
type OrganizationSwitcherProps = {
|
|
165
165
|
authClient: AuthUiClient;
|
|
166
|
+
baseUrl?: string | undefined;
|
|
166
167
|
side?: ComponentProps<typeof DropdownMenuContent>["side"];
|
|
167
168
|
className?: string;
|
|
168
169
|
renderUnauthenticated?: () => ReactNode;
|
|
@@ -177,5 +178,5 @@ type OrganizationSummary = {
|
|
|
177
178
|
slug: string;
|
|
178
179
|
metadata?: unknown;
|
|
179
180
|
};
|
|
180
|
-
export declare function OrganizationSwitcher({ authClient, side, className, renderUnauthenticated, locked, messages, onChange, onCreate, }: OrganizationSwitcherProps): import("react").JSX.Element;
|
|
181
|
+
export declare function OrganizationSwitcher({ authClient, baseUrl, side, className, renderUnauthenticated, locked, messages, onChange, onCreate, }: OrganizationSwitcherProps): import("react").JSX.Element;
|
|
181
182
|
export {};
|
|
@@ -16,7 +16,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "
|
|
|
16
16
|
import { Separator } from "@/components/ui/separator";
|
|
17
17
|
import { cn } from "@/lib/utils";
|
|
18
18
|
import { OrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
19
|
-
import { assetPath, isRecord } from "./utils";
|
|
19
|
+
import { assetPath, assetUrl, isRecord } from "./utils";
|
|
20
20
|
const messages = {
|
|
21
21
|
en: {
|
|
22
22
|
api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
|
|
@@ -254,7 +254,7 @@ const findOrganizationTranslation = (organization, locale = currentOrganizationL
|
|
|
254
254
|
translations.find((translation) => translation.locale === "en") ??
|
|
255
255
|
translations[0]);
|
|
256
256
|
};
|
|
257
|
-
const organizationDisplay = (organization, m) => {
|
|
257
|
+
const organizationDisplay = (organization, m, baseUrl) => {
|
|
258
258
|
const translation = organization
|
|
259
259
|
? findOrganizationTranslation(organization)
|
|
260
260
|
: undefined;
|
|
@@ -263,10 +263,10 @@ const organizationDisplay = (organization, m) => {
|
|
|
263
263
|
organization?.name ||
|
|
264
264
|
m.organization_switcher_label(),
|
|
265
265
|
subtitle: organization?.slug ?? m.organization_switcher_label(),
|
|
266
|
-
image: translation?.icon || translation?.logo
|
|
266
|
+
image: assetUrl(translation?.icon || translation?.logo, baseUrl),
|
|
267
267
|
};
|
|
268
268
|
};
|
|
269
|
-
const organizationFormDefaults = (organization) => {
|
|
269
|
+
const organizationFormDefaults = (organization, baseUrl) => {
|
|
270
270
|
const translations = parseOrganizationMetadata(organization?.metadata).translations;
|
|
271
271
|
const en = translations.find((translation) => translation.locale === "en");
|
|
272
272
|
const fr = translations.find((translation) => translation.locale === "fr");
|
|
@@ -274,13 +274,13 @@ const organizationFormDefaults = (organization) => {
|
|
|
274
274
|
name: organization?.name ?? "",
|
|
275
275
|
slug: organization?.slug ?? "",
|
|
276
276
|
enName: en?.name || organization?.name || "",
|
|
277
|
-
enLogo: en?.logo
|
|
278
|
-
enIcon: en?.icon
|
|
277
|
+
enLogo: assetUrl(en?.logo, baseUrl) || null,
|
|
278
|
+
enIcon: assetUrl(en?.icon, baseUrl) || null,
|
|
279
279
|
enContactEmail: en?.contactEmail ?? "",
|
|
280
280
|
enLocation: en?.location ?? "",
|
|
281
281
|
frName: fr?.name ?? "",
|
|
282
|
-
frLogo: fr?.logo
|
|
283
|
-
frIcon: fr?.icon
|
|
282
|
+
frLogo: assetUrl(fr?.logo, baseUrl) || null,
|
|
283
|
+
frIcon: assetUrl(fr?.icon, baseUrl) || null,
|
|
284
284
|
frContactEmail: fr?.contactEmail ?? "",
|
|
285
285
|
frLocation: fr?.location ?? "",
|
|
286
286
|
};
|
|
@@ -342,7 +342,7 @@ const organizationMetadataFromForm = async (authClient, value, m) => {
|
|
|
342
342
|
}
|
|
343
343
|
return { translations };
|
|
344
344
|
};
|
|
345
|
-
export function OrganizationSwitcher({ authClient, side = "bottom", className, renderUnauthenticated, locked = false, messages, onChange, onCreate, }) {
|
|
345
|
+
export function OrganizationSwitcher({ authClient, baseUrl, side = "bottom", className, renderUnauthenticated, locked = false, messages, onChange, onCreate, }) {
|
|
346
346
|
const labels = organizationSwitcherMessages(messages);
|
|
347
347
|
const m = organizationMessageFns(labels);
|
|
348
348
|
const session = authClient.useSession();
|
|
@@ -399,7 +399,7 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
|
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
};
|
|
402
|
-
const activeDisplay = organizationDisplay(active ?? null, m);
|
|
402
|
+
const activeDisplay = organizationDisplay(active ?? null, m, baseUrl);
|
|
403
403
|
return (_jsxs(OrganizationMessagesContext.Provider, { value: m, children: [_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "ghost", className: cn("h-11 w-full justify-between gap-2 !px-1 !py-0 group-data-[collapsible=icon]:size-8 group-data-[collapsible=icon]:justify-start group-data-[collapsible=icon]:!p-0", className), children: [_jsx(AppBrand, { to: null, label: activeName
|
|
404
404
|
? activeDisplay.name
|
|
405
405
|
: m.organization_switcher_label(), subtitle: activeDisplay.subtitle, 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
|
|
@@ -407,7 +407,7 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
|
|
|
407
407
|
: {}) }), _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: activeDisplay.subtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.image
|
|
408
408
|
? { imageSrc: activeDisplay.image }
|
|
409
409
|
: {}) }) }), 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, !locked && selectableOrganizations.length ? (selectableOrganizations.map((organization) => {
|
|
410
|
-
const display = organizationDisplay(organization, m);
|
|
410
|
+
const display = organizationDisplay(organization, m, baseUrl);
|
|
411
411
|
return (_jsx(DropdownMenuItem, { onClick: async () => {
|
|
412
412
|
const result = await authClient.organization.setActive({
|
|
413
413
|
organizationId: organization.id,
|
|
@@ -424,7 +424,7 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
|
|
|
424
424
|
void loadUserInvitations();
|
|
425
425
|
}, children: [_jsx(Mail, {}), _jsxs("span", { className: "flex flex-1 items-center justify-between gap-3", children: [m.organization_user_invitations_title(), userInvitations.length ? (_jsx(Badge, { variant: "secondary", children: userInvitations.length })) : null] })] }), activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })] })) : null] }) })] }), _jsx(Dialog, { open: dialog === "create", onOpenChange: (open) => {
|
|
426
426
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
427
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, { authClient: authClient, onCreated: async (organization) => {
|
|
427
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, { authClient: authClient, baseUrl: baseUrl, onCreated: async (organization) => {
|
|
428
428
|
onCreate?.(organization);
|
|
429
429
|
setDialog(null);
|
|
430
430
|
const activeResult = await authClient.organization.setActive({
|
|
@@ -435,7 +435,7 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
|
|
|
435
435
|
onChange?.(organization);
|
|
436
436
|
} })] }) }), _jsx(Dialog, { open: dialog === "manage", onOpenChange: (open) => {
|
|
437
437
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
438
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(EditOrganizationSection, { authClient: authClient, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
438
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(EditOrganizationSection, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
439
439
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
440
440
|
}, 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_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, organization: activeOrganization.data, currentUserId: session.data.user.id })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys", onOpenChange: (open) => {
|
|
441
441
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
@@ -517,10 +517,10 @@ const userInvitationColumns = ({ m, actingInvitationId, onAccept, onReject, }) =
|
|
|
517
517
|
},
|
|
518
518
|
]),
|
|
519
519
|
];
|
|
520
|
-
function EditOrganizationSection({ authClient, organization, onUpdated, }) {
|
|
520
|
+
function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated, }) {
|
|
521
521
|
const m = useOrganizationMessages();
|
|
522
522
|
const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
|
|
523
|
-
const defaultValues = organizationFormDefaults(organization);
|
|
523
|
+
const defaultValues = organizationFormDefaults(organization, baseUrl);
|
|
524
524
|
const form = useAppForm({
|
|
525
525
|
defaultValues,
|
|
526
526
|
onSubmit: async ({ value, formApi }) => {
|
|
@@ -592,10 +592,10 @@ function CreateOrganizationSlugAutoFill({ form, }) {
|
|
|
592
592
|
}, [form, name, slugIsDirty]);
|
|
593
593
|
return null;
|
|
594
594
|
}
|
|
595
|
-
function CreateOrganizationSection({ authClient, onCreated, }) {
|
|
595
|
+
function CreateOrganizationSection({ authClient, baseUrl, onCreated, }) {
|
|
596
596
|
const m = useOrganizationMessages();
|
|
597
597
|
const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
|
|
598
|
-
const defaultValues = organizationFormDefaults();
|
|
598
|
+
const defaultValues = organizationFormDefaults(undefined, baseUrl);
|
|
599
599
|
const form = useAppForm({
|
|
600
600
|
defaultValues,
|
|
601
601
|
onSubmit: async ({ value, formApi }) => {
|
|
@@ -169,11 +169,12 @@ type UserButtonMessageKey = keyof (typeof messages)["en"];
|
|
|
169
169
|
export type UserButtonMessages = Partial<Record<UserButtonMessageKey, string>>;
|
|
170
170
|
type UserDropdownProps = {
|
|
171
171
|
authClient: AuthUiClient;
|
|
172
|
+
baseUrl?: string | undefined;
|
|
172
173
|
signOutRedirect?: string;
|
|
173
174
|
side?: ComponentProps<typeof DropdownMenuContent>["side"];
|
|
174
175
|
renderUnauthenticated?: () => ReactNode;
|
|
175
176
|
apiKeyPermissions?: Record<string, string[]>;
|
|
176
177
|
messages?: UserButtonMessages;
|
|
177
178
|
};
|
|
178
|
-
export declare const UserButton: ({ authClient, signOutRedirect, side, renderUnauthenticated, apiKeyPermissions, messages, }: UserDropdownProps) => import("react").JSX.Element;
|
|
179
|
+
export declare const UserButton: ({ authClient, baseUrl, signOutRedirect, side, renderUnauthenticated, apiKeyPermissions, messages, }: UserDropdownProps) => import("react").JSX.Element;
|
|
179
180
|
export {};
|
|
@@ -14,7 +14,7 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, }
|
|
|
14
14
|
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSet, } from "@/components/ui/field";
|
|
15
15
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
16
16
|
import { Separator } from "@/components/ui/separator";
|
|
17
|
-
import { assetPath, isRecord } from "./utils";
|
|
17
|
+
import { assetPath, assetUrl, isRecord } from "./utils";
|
|
18
18
|
const messages = {
|
|
19
19
|
en: {
|
|
20
20
|
api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
|
|
@@ -218,7 +218,7 @@ const presignUserImageUpload = async (authClient, file, m) => {
|
|
|
218
218
|
}
|
|
219
219
|
return { uploadUrl, url };
|
|
220
220
|
};
|
|
221
|
-
export const UserButton = ({ authClient, signOutRedirect = "/", side = "bottom", renderUnauthenticated, apiKeyPermissions, messages, }) => {
|
|
221
|
+
export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side = "bottom", renderUnauthenticated, apiKeyPermissions, messages, }) => {
|
|
222
222
|
const labels = userButtonMessages(messages);
|
|
223
223
|
const m = userButtonMessageFns(labels);
|
|
224
224
|
const navigate = useNavigate();
|
|
@@ -233,7 +233,7 @@ export const UserButton = ({ authClient, signOutRedirect = "/", side = "bottom",
|
|
|
233
233
|
}
|
|
234
234
|
const displayName = session.user.name.trim();
|
|
235
235
|
const displayEmail = session.user.email.trim();
|
|
236
|
-
const displayImage = session.user.image
|
|
236
|
+
const displayImage = assetUrl(session.user.image, baseUrl);
|
|
237
237
|
const signOut = async () => {
|
|
238
238
|
const redirectUrl = signOutRedirect.startsWith("http")
|
|
239
239
|
? signOutRedirect
|
package/dist/components/utils.js
CHANGED
|
@@ -10,3 +10,13 @@ export const assetPath = (value) => {
|
|
|
10
10
|
return value;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
+
export const assetUrl = (value, baseUrl) => {
|
|
14
|
+
const path = value?.trim();
|
|
15
|
+
if (!path)
|
|
16
|
+
return "";
|
|
17
|
+
if (!path.startsWith("/api/assets/"))
|
|
18
|
+
return path;
|
|
19
|
+
if (!baseUrl?.trim())
|
|
20
|
+
return path;
|
|
21
|
+
return new URL(path, baseUrl).toString();
|
|
22
|
+
};
|