@krak-stack/auth 0.1.16 → 0.1.18
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.
|
@@ -209,7 +209,17 @@ const isOrganizationSlugConflict = (error) => {
|
|
|
209
209
|
});
|
|
210
210
|
};
|
|
211
211
|
const nullableString = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
|
|
212
|
-
const
|
|
212
|
+
const assetPath = (value) => {
|
|
213
|
+
if (!value?.trim())
|
|
214
|
+
return null;
|
|
215
|
+
try {
|
|
216
|
+
const url = new URL(value);
|
|
217
|
+
return url.pathname.startsWith("/api/assets/") ? url.pathname : value;
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
213
223
|
const parsePresignedUpload = (value, m) => {
|
|
214
224
|
if (!isRecord(value) ||
|
|
215
225
|
typeof value.uploadUrl !== "string" ||
|
|
@@ -219,18 +229,16 @@ const parsePresignedUpload = (value, m) => {
|
|
|
219
229
|
return { uploadUrl: value.uploadUrl, url: value.url };
|
|
220
230
|
};
|
|
221
231
|
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
222
|
-
const uploadOrganizationLogo = async (file, m) => {
|
|
232
|
+
const uploadOrganizationLogo = async (authClient, file, m) => {
|
|
223
233
|
const contentType = file.type || "image/png";
|
|
224
|
-
const
|
|
234
|
+
const presignResult = await authClient.$fetch("../organizations/logo/presign", {
|
|
225
235
|
method: "POST",
|
|
226
|
-
|
|
227
|
-
headers: { "Content-Type": "application/json" },
|
|
228
|
-
body: JSON.stringify({ fileName: file.name, contentType }),
|
|
236
|
+
body: { fileName: file.name, contentType },
|
|
229
237
|
});
|
|
230
|
-
if (
|
|
238
|
+
if (presignResult.error) {
|
|
231
239
|
throw new Error(m.organization_logo_upload_error());
|
|
232
240
|
}
|
|
233
|
-
const presigned = parsePresignedUpload(
|
|
241
|
+
const presigned = parsePresignedUpload(presignResult.data, m);
|
|
234
242
|
const uploadResponse = await fetch(presigned.uploadUrl, {
|
|
235
243
|
method: "PUT",
|
|
236
244
|
headers: { "Content-Type": contentType },
|
|
@@ -239,12 +247,13 @@ const uploadOrganizationLogo = async (file, m) => {
|
|
|
239
247
|
if (!uploadResponse.ok) {
|
|
240
248
|
throw new Error(m.organization_logo_upload_error());
|
|
241
249
|
}
|
|
242
|
-
return
|
|
250
|
+
return assetPath(presigned.url);
|
|
243
251
|
};
|
|
244
252
|
const currentOrganizationLocale = () => getLocale() === "fr" ? "fr" : "en";
|
|
245
253
|
const parseOrganizationMetadata = (metadata) => {
|
|
246
254
|
try {
|
|
247
|
-
|
|
255
|
+
const value = typeof metadata === "string" ? JSON.parse(metadata) : metadata;
|
|
256
|
+
return Schema.decodeUnknownSync(OrganizationMetadata)(value);
|
|
248
257
|
}
|
|
249
258
|
catch {
|
|
250
259
|
return { translations: [] };
|
|
@@ -265,7 +274,7 @@ const organizationDisplay = (organization, m) => {
|
|
|
265
274
|
organization?.name ||
|
|
266
275
|
m.organization_switcher_label(),
|
|
267
276
|
subtitle: organization?.slug ?? m.organization_switcher_label(),
|
|
268
|
-
|
|
277
|
+
image: translation?.icon || translation?.logo || undefined,
|
|
269
278
|
};
|
|
270
279
|
};
|
|
271
280
|
const organizationFormDefaults = (organization) => {
|
|
@@ -276,22 +285,24 @@ const organizationFormDefaults = (organization) => {
|
|
|
276
285
|
name: organization?.name ?? "",
|
|
277
286
|
slug: organization?.slug ?? "",
|
|
278
287
|
enName: en?.name || organization?.name || "",
|
|
279
|
-
enLogo: null,
|
|
280
|
-
|
|
281
|
-
enIcon: null,
|
|
282
|
-
enIconUrl: en?.icon ?? "",
|
|
288
|
+
enLogo: en?.logo ?? null,
|
|
289
|
+
enIcon: en?.icon ?? null,
|
|
283
290
|
enContactEmail: en?.contactEmail ?? "",
|
|
284
291
|
enLocation: en?.location ?? "",
|
|
285
292
|
frName: fr?.name ?? "",
|
|
286
|
-
frLogo: null,
|
|
287
|
-
|
|
288
|
-
frIcon: null,
|
|
289
|
-
frIconUrl: fr?.icon ?? "",
|
|
293
|
+
frLogo: fr?.logo ?? null,
|
|
294
|
+
frIcon: fr?.icon ?? null,
|
|
290
295
|
frContactEmail: fr?.contactEmail ?? "",
|
|
291
296
|
frLocation: fr?.location ?? "",
|
|
292
297
|
};
|
|
293
298
|
};
|
|
294
|
-
const organizationLogoFromForm = async (
|
|
299
|
+
const organizationLogoFromForm = async (authClient, value, m) => {
|
|
300
|
+
if (value instanceof File)
|
|
301
|
+
return await uploadOrganizationLogo(authClient, value, m);
|
|
302
|
+
if (typeof value === "string")
|
|
303
|
+
return assetPath(value);
|
|
304
|
+
return null;
|
|
305
|
+
};
|
|
295
306
|
const organizationRoles = ["owner", "admin", "member"];
|
|
296
307
|
const normalizeOrganizationRole = (role) => role === "owner" || role === "admin" || role === "member" ? role : "member";
|
|
297
308
|
const organizationRoleLabel = (role, m) => {
|
|
@@ -312,14 +323,14 @@ const initialsFromName = (name) => name
|
|
|
312
323
|
.map((part) => part[0])
|
|
313
324
|
.join("")
|
|
314
325
|
.toUpperCase() || "?";
|
|
315
|
-
const organizationMetadataFromForm = async (value, m) => {
|
|
326
|
+
const organizationMetadataFromForm = async (authClient, value, m) => {
|
|
316
327
|
const translations = [];
|
|
317
328
|
const enName = value.enName.trim() || value.name.trim();
|
|
318
329
|
const frName = value.frName.trim();
|
|
319
|
-
const enLogo = await organizationLogoFromForm(
|
|
320
|
-
const enIcon = await organizationLogoFromForm(
|
|
321
|
-
const frLogo = await organizationLogoFromForm(
|
|
322
|
-
const frIcon = await organizationLogoFromForm(
|
|
330
|
+
const enLogo = await organizationLogoFromForm(authClient, value.enLogo, m);
|
|
331
|
+
const enIcon = await organizationLogoFromForm(authClient, value.enIcon, m);
|
|
332
|
+
const frLogo = await organizationLogoFromForm(authClient, value.frLogo, m);
|
|
333
|
+
const frIcon = await organizationLogoFromForm(authClient, value.frIcon, m);
|
|
323
334
|
if (enName) {
|
|
324
335
|
translations.push({
|
|
325
336
|
locale: "en",
|
|
@@ -402,10 +413,10 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
|
|
|
402
413
|
const activeDisplay = organizationDisplay(active ?? null, m);
|
|
403
414
|
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
415
|
? activeDisplay.name
|
|
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.
|
|
406
|
-
? { imageSrc: activeDisplay.
|
|
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.
|
|
408
|
-
? { imageSrc: activeDisplay.
|
|
416
|
+
: 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
|
|
417
|
+
? { imageSrc: activeDisplay.image }
|
|
418
|
+
: {}) }), _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
|
|
419
|
+
? { imageSrc: activeDisplay.image }
|
|
409
420
|
: {}) }) }), 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
421
|
const display = organizationDisplay(organization, m);
|
|
411
422
|
return (_jsx(DropdownMenuItem, { onClick: async () => {
|
|
@@ -416,7 +427,7 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
|
|
|
416
427
|
await refresh();
|
|
417
428
|
onChange?.(organization);
|
|
418
429
|
}
|
|
419
|
-
}, children: _jsx(AppBrand, { to: null, label: display.name, subtitle: display.subtitle, icon: Building2, className: "w-full text-left [&>div:first-child]:size-7", ...(display.
|
|
430
|
+
}, children: _jsx(AppBrand, { to: null, label: display.name, subtitle: display.subtitle, icon: Building2, className: "w-full text-left [&>div:first-child]:size-7", ...(display.image ? { imageSrc: display.image } : {}) }) }, organization.id));
|
|
420
431
|
})) : !locked && !organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: active
|
|
421
432
|
? m.organization_switcher_no_other_organizations()
|
|
422
433
|
: m.organization_switcher_empty() })) : null, _jsx(DropdownMenuSeparator, {}), !locked ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("create"), children: [_jsx(Plus, {}), m.organization_create_title()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => {
|
|
@@ -525,45 +536,57 @@ function EditOrganizationSection({ authClient, organization, onUpdated, }) {
|
|
|
525
536
|
defaultValues,
|
|
526
537
|
onSubmit: async ({ value, formApi }) => {
|
|
527
538
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
539
|
+
try {
|
|
540
|
+
const name = value.name.trim();
|
|
541
|
+
const slug = value.slug.trim().toLowerCase();
|
|
542
|
+
const metadata = await organizationMetadataFromForm(authClient, value, m);
|
|
543
|
+
const result = await authClient.organization.update({
|
|
544
|
+
organizationId: organization.id,
|
|
545
|
+
data: { name, slug, metadata },
|
|
546
|
+
});
|
|
547
|
+
if (result.error) {
|
|
548
|
+
formApi.setErrorMap({
|
|
549
|
+
onSubmit: {
|
|
550
|
+
form: result.error.message ?? m.organization_update_error(),
|
|
551
|
+
fields: {},
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
await onUpdated();
|
|
557
|
+
}
|
|
558
|
+
catch (cause) {
|
|
536
559
|
formApi.setErrorMap({
|
|
537
560
|
onSubmit: {
|
|
538
|
-
form:
|
|
561
|
+
form: cause instanceof Error
|
|
562
|
+
? cause.message
|
|
563
|
+
: m.organization_update_error(),
|
|
539
564
|
fields: {},
|
|
540
565
|
},
|
|
541
566
|
});
|
|
542
|
-
return;
|
|
543
567
|
}
|
|
544
|
-
await onUpdated();
|
|
545
568
|
},
|
|
546
569
|
});
|
|
547
570
|
return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.AppForm, { children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
|
|
548
571
|
event.preventDefault();
|
|
549
572
|
event.stopPropagation();
|
|
550
573
|
form.handleSubmit();
|
|
551
|
-
}, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), required: true })) }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(),
|
|
574
|
+
}, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), required: true })) }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), size: {
|
|
552
575
|
width: 175,
|
|
553
576
|
height: 50,
|
|
554
577
|
suggestedWidth: 350,
|
|
555
578
|
suggestedHeight: 100,
|
|
556
|
-
} })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(),
|
|
579
|
+
} })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
|
|
557
580
|
width: 96,
|
|
558
581
|
height: 96,
|
|
559
582
|
suggestedWidth: 512,
|
|
560
583
|
suggestedHeight: 512,
|
|
561
|
-
} })) }), _jsx(form.AppField, { name: "enContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "enLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })) : (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "fr", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "frName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name() })) }), _jsx(form.AppField, { name: "frLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(),
|
|
584
|
+
} })) }), _jsx(form.AppField, { name: "enContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "enLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })) : (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "fr", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "frName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name() })) }), _jsx(form.AppField, { name: "frLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), size: {
|
|
562
585
|
width: 175,
|
|
563
586
|
height: 50,
|
|
564
587
|
suggestedWidth: 350,
|
|
565
588
|
suggestedHeight: 100,
|
|
566
|
-
} })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(),
|
|
589
|
+
} })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
|
|
567
590
|
width: 96,
|
|
568
591
|
height: 96,
|
|
569
592
|
suggestedWidth: 512,
|
|
@@ -588,61 +611,73 @@ function CreateOrganizationSection({ authClient, onCreated, }) {
|
|
|
588
611
|
defaultValues,
|
|
589
612
|
onSubmit: async ({ value, formApi }) => {
|
|
590
613
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
if (
|
|
614
|
+
try {
|
|
615
|
+
const name = value.name.trim();
|
|
616
|
+
const slug = (value.slug.trim() || slugify(name)).toLowerCase();
|
|
617
|
+
const metadata = await organizationMetadataFromForm(authClient, {
|
|
618
|
+
...value,
|
|
619
|
+
name,
|
|
620
|
+
slug,
|
|
621
|
+
}, m);
|
|
622
|
+
const result = await authClient.organization.create({
|
|
623
|
+
name,
|
|
624
|
+
slug,
|
|
625
|
+
metadata,
|
|
626
|
+
});
|
|
627
|
+
if (result.error) {
|
|
628
|
+
if (isOrganizationSlugConflict(result.error)) {
|
|
629
|
+
formApi.setErrorMap({
|
|
630
|
+
onSubmit: {
|
|
631
|
+
fields: {
|
|
632
|
+
slug: { message: m.organization_create_slug_conflict() },
|
|
633
|
+
},
|
|
634
|
+
},
|
|
635
|
+
});
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
605
638
|
formApi.setErrorMap({
|
|
606
639
|
onSubmit: {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
},
|
|
640
|
+
form: result.error.message ?? m.organization_create_error(),
|
|
641
|
+
fields: {},
|
|
610
642
|
},
|
|
611
643
|
});
|
|
612
644
|
return;
|
|
613
645
|
}
|
|
646
|
+
form.reset();
|
|
647
|
+
await onCreated(result.data);
|
|
648
|
+
}
|
|
649
|
+
catch (cause) {
|
|
614
650
|
formApi.setErrorMap({
|
|
615
651
|
onSubmit: {
|
|
616
|
-
form:
|
|
652
|
+
form: cause instanceof Error
|
|
653
|
+
? cause.message
|
|
654
|
+
: m.organization_create_error(),
|
|
617
655
|
fields: {},
|
|
618
656
|
},
|
|
619
657
|
});
|
|
620
|
-
return;
|
|
621
658
|
}
|
|
622
|
-
form.reset();
|
|
623
|
-
await onCreated(result.data);
|
|
624
659
|
},
|
|
625
660
|
});
|
|
626
661
|
return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.AppForm, { children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
|
|
627
662
|
event.preventDefault();
|
|
628
663
|
event.stopPropagation();
|
|
629
664
|
form.handleSubmit();
|
|
630
|
-
}, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), description: m.organization_slug_description() })) }), _jsx(CreateOrganizationSlugAutoFill, { form: form }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(),
|
|
665
|
+
}, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), description: m.organization_slug_description() })) }), _jsx(CreateOrganizationSlugAutoFill, { form: form }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), size: {
|
|
631
666
|
width: 175,
|
|
632
667
|
height: 50,
|
|
633
668
|
suggestedWidth: 350,
|
|
634
669
|
suggestedHeight: 100,
|
|
635
|
-
} })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(),
|
|
670
|
+
} })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
|
|
636
671
|
width: 96,
|
|
637
672
|
height: 96,
|
|
638
673
|
suggestedWidth: 512,
|
|
639
674
|
suggestedHeight: 512,
|
|
640
|
-
} })) }), _jsx(form.AppField, { name: "enContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "enLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })) : (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "fr", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "frName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name() })) }), _jsx(form.AppField, { name: "frLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(),
|
|
675
|
+
} })) }), _jsx(form.AppField, { name: "enContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "enLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })) : (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "fr", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "frName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name() })) }), _jsx(form.AppField, { name: "frLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), size: {
|
|
641
676
|
width: 175,
|
|
642
677
|
height: 50,
|
|
643
678
|
suggestedWidth: 350,
|
|
644
679
|
suggestedHeight: 100,
|
|
645
|
-
} })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(),
|
|
680
|
+
} })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
|
|
646
681
|
width: 96,
|
|
647
682
|
height: 96,
|
|
648
683
|
suggestedWidth: 512,
|
|
@@ -201,25 +201,18 @@ const userButtonMessageFns = (labels) => {
|
|
|
201
201
|
const UserButtonMessagesContext = createContext(userButtonMessageFns(userButtonMessages()));
|
|
202
202
|
const useUserButtonMessages = () => useContext(UserButtonMessagesContext);
|
|
203
203
|
const isFile = (value) => value instanceof File;
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
"
|
|
207
|
-
const
|
|
208
|
-
const response = await fetch(authUrl("/api/auth/image/presign"), {
|
|
204
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
205
|
+
const presignUserImageUpload = async (authClient, file, m) => {
|
|
206
|
+
const contentType = file.type || "image/png";
|
|
207
|
+
const result = await authClient.$fetch("/image/presign", {
|
|
209
208
|
method: "POST",
|
|
210
|
-
|
|
211
|
-
headers: { "Content-Type": "application/json" },
|
|
212
|
-
body: JSON.stringify({ fileName: file.name, contentType: file.type }),
|
|
209
|
+
body: { fileName: file.name, contentType },
|
|
213
210
|
});
|
|
214
|
-
if (!
|
|
211
|
+
if (result.error || !isRecord(result.data)) {
|
|
215
212
|
throw new Error(m.user_profile_image_upload_error());
|
|
216
213
|
}
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
throw new Error(m.user_profile_image_upload_error());
|
|
220
|
-
}
|
|
221
|
-
const uploadUrl = Reflect.get(body, "uploadUrl");
|
|
222
|
-
const url = Reflect.get(body, "url");
|
|
214
|
+
const uploadUrl = Reflect.get(result.data, "uploadUrl");
|
|
215
|
+
const url = Reflect.get(result.data, "url");
|
|
223
216
|
if (typeof uploadUrl !== "string" || typeof url !== "string") {
|
|
224
217
|
throw new Error(m.user_profile_image_upload_error());
|
|
225
218
|
}
|
|
@@ -240,9 +233,7 @@ export const UserButton = ({ authClient, signOutRedirect = "/", side = "bottom",
|
|
|
240
233
|
}
|
|
241
234
|
const displayName = session.user.name.trim();
|
|
242
235
|
const displayEmail = session.user.email.trim();
|
|
243
|
-
const displayImage = session.user.image?.trim()
|
|
244
|
-
? authUrl(session.user.image.trim())
|
|
245
|
-
: "";
|
|
236
|
+
const displayImage = session.user.image?.trim() ?? "";
|
|
246
237
|
const signOut = async () => {
|
|
247
238
|
const redirectUrl = signOutRedirect.startsWith("http")
|
|
248
239
|
? signOutRedirect
|
|
@@ -255,10 +246,10 @@ export const UserButton = ({ authClient, signOutRedirect = "/", side = "bottom",
|
|
|
255
246
|
const imageFile = isFile(values.image) ? values.image : null;
|
|
256
247
|
const image = imageFile
|
|
257
248
|
? await (async () => {
|
|
258
|
-
const presigned = await presignUserImageUpload(imageFile, m);
|
|
249
|
+
const presigned = await presignUserImageUpload(authClient, imageFile, m);
|
|
259
250
|
const uploadResponse = await fetch(presigned.uploadUrl, {
|
|
260
251
|
method: "PUT",
|
|
261
|
-
headers: { "Content-Type": imageFile.type },
|
|
252
|
+
headers: { "Content-Type": imageFile.type || "image/png" },
|
|
262
253
|
body: imageFile,
|
|
263
254
|
});
|
|
264
255
|
if (!uploadResponse.ok) {
|