Browse Source

fix problem with bad URL parameter name in a deep link

pull/131/head
Trent Larson 2 months ago
parent
commit
e865913f72
  1. 54
      src/services/deepLinks.ts
  2. 2
      src/types/deepLinks.ts

54
src/services/deepLinks.ts

@ -71,6 +71,28 @@ export class DeepLinkHandler {
} }
/** /**
* Maps deep link routes to their corresponding Vue router names and optional parameter keys.
*
* The paramKey is used to extract the parameter from the route path,
* because "router.replace" expects the right parameter name for the route.
* The default is "id".
*/
private readonly ROUTE_MAP: Record<string, { name: string, paramKey?: string }> = {
"user-profile": { name: "user-profile" },
"project-details": { name: "project-details" },
"onboard-meeting-setup": { name: "onboard-meeting-setup" },
"invite-one-accept": { name: "invite-one-accept" },
"contact-import": { name: "contact-import" },
"confirm-gift": { name: "confirm-gift" },
claim: { name: "claim" },
"claim-cert": { name: "claim-cert" },
"claim-add-raw": { name: "claim-add-raw" },
"contact-edit": { name: "contact-edit", paramKey: "did" },
contacts: { name: "contacts" },
did: { name: "did", paramKey: "did" },
};
/**
* Parses deep link URL into path, params and query components. * Parses deep link URL into path, params and query components.
* Validates URL structure using Zod schemas. * Validates URL structure using Zod schemas.
* *
@ -101,11 +123,16 @@ export class DeepLinkHandler {
}); });
} }
return { const params: Record<string, string> = {};
path: routePath, if (param) {
params: param ? { id: param } : {}, if (this.ROUTE_MAP[routePath].paramKey) {
query, params[this.ROUTE_MAP[routePath].paramKey] = param;
}; } else {
params['id'] = param;
}
}
return { path: routePath, params, query };
} }
/** /**
@ -153,28 +180,13 @@ export class DeepLinkHandler {
params: Record<string, string>, params: Record<string, string>,
query: Record<string, string>, query: Record<string, string>,
): Promise<void> { ): Promise<void> {
const routeMap: Record<string, string> = {
"user-profile": "user-profile",
"project-details": "project-details",
"onboard-meeting-setup": "onboard-meeting-setup",
"invite-one-accept": "invite-one-accept",
"contact-import": "contact-import",
"confirm-gift": "confirm-gift",
claim: "claim",
"claim-cert": "claim-cert",
"claim-add-raw": "claim-add-raw",
"contact-edit": "contact-edit",
contacts: "contacts",
did: "did",
};
// First try to validate the route path // First try to validate the route path
let routeName: string; let routeName: string;
try { try {
// Validate route exists // Validate route exists
const validRoute = routeSchema.parse(path) as DeepLinkRoute; const validRoute = routeSchema.parse(path) as DeepLinkRoute;
routeName = routeMap[validRoute]; routeName = this.ROUTE_MAP[validRoute].name;
} catch (error) { } catch (error) {
// Log the invalid route attempt // Log the invalid route attempt
logConsoleAndDb(`[DeepLink] Invalid route path: ${path}`, true); logConsoleAndDb(`[DeepLink] Invalid route path: ${path}`, true);

2
src/types/deepLinks.ts

@ -94,7 +94,7 @@ export const deepLinkSchemas = {
contacts: z.string(), // JSON string of contacts array contacts: z.string(), // JSON string of contacts array
}), }),
did: z.object({ did: z.object({
id: z.string(), did: z.string(),
}), }),
}; };

Loading…
Cancel
Save