Skip to content

Commit 4c36f40

Browse files
committed
Fix API key redirect URL on in-app wallet settings and unresponsive general project settings page
1 parent 6994310 commit 4c36f40

File tree

3 files changed

+60
-26
lines changed

3 files changed

+60
-26
lines changed

apps/dashboard/src/app/team/[team_slug]/[project_slug]/settings/ProjectGeneralSettingsPage.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import { type FieldArrayWithId, useFieldArray } from "react-hook-form";
3535
import { toast } from "sonner";
3636
import { joinWithComma, toArrFromList } from "utils/string";
3737
import {
38-
type ApiKeyValidationSchema,
3938
HIDDEN_SERVICES,
40-
apiKeyValidationSchema,
39+
type ProjectSettingsPageFormSchema,
40+
projectSettingsPageFormSchema,
4141
} from "../../../../../components/settings/ApiKeys/validations";
4242

4343
type EditProjectUIPaths = {
@@ -86,16 +86,16 @@ interface EditApiKeyProps {
8686
showNebulaSettings: boolean;
8787
}
8888

89-
type UpdateAPIForm = UseFormReturn<ApiKeyValidationSchema>;
89+
type UpdateAPIForm = UseFormReturn<ProjectSettingsPageFormSchema>;
9090

9191
export const ProjectGeneralSettingsPageUI: React.FC<EditApiKeyProps> = (
9292
props,
9393
) => {
9494
const { apiKey, updateMutation, deleteMutation } = props;
9595
const trackEvent = useTrack();
9696
const router = useDashboardRouter();
97-
const form = useForm<ApiKeyValidationSchema>({
98-
resolver: zodResolver(apiKeyValidationSchema),
97+
const form = useForm<ProjectSettingsPageFormSchema>({
98+
resolver: zodResolver(projectSettingsPageFormSchema),
9999
defaultValues: {
100100
name: apiKey.name,
101101
domains: joinWithComma(apiKey.domains),
@@ -484,7 +484,7 @@ function EnabledServicesSetting(props: {
484484
});
485485
const handleAction = (
486486
srvIdx: number,
487-
srv: FieldArrayWithId<ApiKeyValidationSchema, "services", "id">,
487+
srv: FieldArrayWithId<ProjectSettingsPageFormSchema, "services", "id">,
488488
actionName: string,
489489
checked: boolean,
490490
) => {

apps/dashboard/src/components/embedded-wallets/Configure/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ function AuthEndpointFields(props: {
422422
name: "customAuthEndpoint.customHeaders",
423423
});
424424

425+
const expandCustomAuthEndpointField =
426+
form.watch("customAuthEndpoint")?.authEndpoint !== undefined &&
427+
canEditAdvancedFeatures;
428+
425429
return (
426430
<div>
427431
<SwitchContainer
@@ -445,9 +449,7 @@ function AuthEndpointFields(props: {
445449
>
446450
<GatedSwitch
447451
trackingLabel="customAuthEndpoint"
448-
checked={
449-
!!form.watch("customAuthEndpoint") && canEditAdvancedFeatures
450-
}
452+
checked={expandCustomAuthEndpointField}
451453
upgradeRequired={!canEditAdvancedFeatures}
452454
onCheckedChange={(checked) => {
453455
form.setValue(
@@ -464,7 +466,7 @@ function AuthEndpointFields(props: {
464466
</SwitchContainer>
465467

466468
<AdvancedConfigurationContainer
467-
show={canEditAdvancedFeatures && !!form.watch("customAuthEndpoint")}
469+
show={expandCustomAuthEndpointField}
468470
className="grid grid-cols-1 gap-6 lg:grid-cols-2"
469471
>
470472
<FormField

apps/dashboard/src/components/settings/ApiKeys/validations.ts

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,56 @@ export const apiKeyCreateValidationSchema = z.object({
9595
services: servicesValidation,
9696
});
9797

98-
export const apiKeyValidationSchema = z.object({
98+
function isValidRedirectURI(uri: string) {
99+
// whitespace is not allowed
100+
if (/\s/g.test(uri)) {
101+
return false;
102+
}
103+
104+
// foo://... is allowed
105+
if (uri.includes("://")) {
106+
return true;
107+
}
108+
109+
// localhost:... is allowed
110+
const domain = uri.split(":")[0];
111+
if (domain === "localhost") {
112+
return true;
113+
}
114+
115+
// valid url is allowed
116+
try {
117+
new URL(uri);
118+
return true;
119+
} catch {
120+
// invalid
121+
}
122+
123+
// everything else is invalid
124+
return false;
125+
}
126+
127+
const redirectUriSchema = z
128+
.string()
129+
.refine((str) => validStrList(str, isValidRedirectURI), {
130+
message:
131+
"Some of the redirect URIs are invalid. Make sure they are valid URIs and do not contain spaces.",
132+
})
133+
.refine((str) => str !== "*", {
134+
message: "Wildcard redirect URIs are not allowed",
135+
});
136+
137+
// TODO: move this schema to project settings folder in separate PR
138+
export const projectSettingsPageFormSchema = z.object({
99139
name: nameValidation,
100140
domains: domainsValidation,
101141
services: servicesValidation,
102142
bundleIds: z.string().refine((str) => validStrList(str, RE_BUNDLE_ID), {
103143
message: "Some of the bundle ids are invalid",
104144
}),
105-
redirectUrls: z
106-
.string()
107-
.refine(
108-
(str) =>
109-
validStrList(str, (url) => url.includes("://") && !/\s/g.test(url)),
110-
{
111-
message:
112-
"Some of the redirect URIs are invalid. Make sure they are valid URIs and do not contain spaces.",
113-
},
114-
)
115-
.refine((str) => str !== "*", {
116-
message: "Wildcard redirect URIs are not allowed",
117-
}),
145+
// no strict validation for redirectUrls, because project general page does not render redirectUrls form field
146+
// so if the user has already saved an invalid `redirectUrls` on in-app wallet project settings page ( which is fixed now ) - it won't prevent them from updating the general project settings
147+
redirectUrls: z.string(),
118148
});
119149

120150
export const apiKeyEmbeddedWalletsValidationSchema = z.object({
@@ -127,7 +157,7 @@ export const apiKeyEmbeddedWalletsValidationSchema = z.object({
127157
applicationImageUrl: applicationImageUrlValidation,
128158
}),
129159
]),
130-
redirectUrls: z.union([z.undefined(), z.string()]),
160+
redirectUrls: redirectUriSchema,
131161
});
132162

133163
export const apiKeyPayConfigValidationSchema = z.object({
@@ -138,7 +168,9 @@ export type ApiKeyCreateValidationSchema = z.infer<
138168
typeof apiKeyCreateValidationSchema
139169
>;
140170

141-
export type ApiKeyValidationSchema = z.infer<typeof apiKeyValidationSchema>;
171+
export type ProjectSettingsPageFormSchema = z.infer<
172+
typeof projectSettingsPageFormSchema
173+
>;
142174

143175
export type ApiKeyEmbeddedWalletsValidationSchema = z.infer<
144176
typeof apiKeyEmbeddedWalletsValidationSchema

0 commit comments

Comments
 (0)