@krak-stack/auth 0.1.18 → 0.1.19
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.
|
@@ -16,6 +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
20
|
const messages = {
|
|
20
21
|
en: {
|
|
21
22
|
api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
|
|
@@ -209,17 +210,6 @@ const isOrganizationSlugConflict = (error) => {
|
|
|
209
210
|
});
|
|
210
211
|
};
|
|
211
212
|
const nullableString = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
|
|
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
|
-
};
|
|
223
213
|
const parsePresignedUpload = (value, m) => {
|
|
224
214
|
if (!isRecord(value) ||
|
|
225
215
|
typeof value.uploadUrl !== "string" ||
|
|
@@ -228,7 +218,6 @@ const parsePresignedUpload = (value, m) => {
|
|
|
228
218
|
}
|
|
229
219
|
return { uploadUrl: value.uploadUrl, url: value.url };
|
|
230
220
|
};
|
|
231
|
-
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
232
221
|
const uploadOrganizationLogo = async (authClient, file, m) => {
|
|
233
222
|
const contentType = file.type || "image/png";
|
|
234
223
|
const presignResult = await authClient.$fetch("../organizations/logo/presign", {
|
|
@@ -14,6 +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
18
|
const messages = {
|
|
18
19
|
en: {
|
|
19
20
|
api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
|
|
@@ -201,7 +202,6 @@ const userButtonMessageFns = (labels) => {
|
|
|
201
202
|
const UserButtonMessagesContext = createContext(userButtonMessageFns(userButtonMessages()));
|
|
202
203
|
const useUserButtonMessages = () => useContext(UserButtonMessagesContext);
|
|
203
204
|
const isFile = (value) => value instanceof File;
|
|
204
|
-
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
205
205
|
const presignUserImageUpload = async (authClient, file, m) => {
|
|
206
206
|
const contentType = file.type || "image/png";
|
|
207
207
|
const result = await authClient.$fetch("/image/presign", {
|
|
@@ -255,10 +255,10 @@ export const UserButton = ({ authClient, signOutRedirect = "/", side = "bottom",
|
|
|
255
255
|
if (!uploadResponse.ok) {
|
|
256
256
|
throw new Error(m.user_profile_image_upload_error());
|
|
257
257
|
}
|
|
258
|
-
return presigned.url;
|
|
258
|
+
return assetPath(presigned.url);
|
|
259
259
|
})()
|
|
260
260
|
: typeof values.image === "string"
|
|
261
|
-
? values.image
|
|
261
|
+
? assetPath(values.image)
|
|
262
262
|
: null;
|
|
263
263
|
const result = await authClient.updateUser({
|
|
264
264
|
name: values.name.trim(),
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const isRecord = (value) => typeof value === "object" && value !== null;
|
|
2
|
+
export const assetPath = (value) => {
|
|
3
|
+
if (!value?.trim())
|
|
4
|
+
return null;
|
|
5
|
+
try {
|
|
6
|
+
const url = new URL(value);
|
|
7
|
+
return url.pathname.startsWith("/api/assets/") ? url.pathname : value;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
};
|