Dealer_Onboarding_Backend/src/common/utils/frontendUrl.ts

29 lines
1.3 KiB
TypeScript

/**
* Portal base URL for emails, WhatsApp, SLA alerts, and notifications.
* Set `FRONTEND_URL` in backend `.env` (e.g. https://dealeronboarding-uat.royalenfield.com).
*/
export function getFrontendBaseUrl(): string {
return (process.env.FRONTEND_URL || 'http://localhost:5173').replace(/\/$/, '');
}
/**
* Portal URL for prospects / applicants — i.e. users with `Prospective Dealer` role.
*
* Internal pages like `/applications/:id` are admin-only and a prospect would just see
* a forbidden page, so applicant-facing emails must always send them through their
* own portal (`/prospective-login` → OTP → `/prospective-dashboard`).
*
* Pass `applicationId` to deep-link to a specific application — the login page reads
* the `next` query parameter and routes the prospect there after OTP verification.
*
* Note: The route is `/prospective-login` (full word). Older code mistakenly used
* `/prospect-login` (singular) which 404s — use this helper to avoid the typo.
*/
export function getProspectPortalUrl(applicationId?: string): string {
const base = getFrontendBaseUrl();
if (!applicationId) return `${base}/prospective-login`;
const next = encodeURIComponent(`/prospective-dashboard/application/${applicationId}`);
return `${base}/prospective-login?next=${next}`;
}