Skip to content

Commit

Permalink
add forward to param
Browse files Browse the repository at this point in the history
  • Loading branch information
rushatgabhane committed Jun 20, 2024
1 parent cfcc93b commit fb58fad
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,23 @@ import type AssertTypesNotEqual from './types/utils/AssertTypesNotEqual';
/**
* Builds a URL with an encoded URI component for the `backTo` param which can be added to the end of URLs
*/
function getUrlWithBackToParam<TUrl extends string>(url: TUrl, backTo?: string): `${TUrl}` | `${TUrl}?backTo=${string}` | `${TUrl}&backTo=${string}` {
function getUrlWithBackToParam<TUrl extends string>(
url: TUrl,
backTo?: string,
forwardTo?: string,
):
| `${TUrl}`
| `${TUrl}?backTo=${string}`
| `${TUrl}&backTo=${string}`
| `${TUrl}?backTo=${string}?forwardTo=${string}`
| `${TUrl}?backTo=${string}&forwardTo=${string}`
| `${TUrl}&backTo=${string}?forwardTo=${string}`
| `${TUrl}&backTo=${string}&forwardTo=${string}`
| `${TUrl}?forwardTo=${string}`
| `${TUrl}&forwardTo=${string}` {
const backToParam = backTo ? (`${url.includes('?') ? '&' : '?'}backTo=${encodeURIComponent(backTo)}` as const) : '';
return `${url}${backToParam}` as const;
const forwardToParam = forwardTo ? (`${url.includes('?') || backToParam ? '&' : '?'}forwardTo=${encodeURIComponent(forwardTo)}` as const) : '';
return `${url}${backToParam}${forwardToParam}` as const;
}

const PUBLIC_SCREENS_ROUTES = {
Expand Down Expand Up @@ -189,7 +203,7 @@ const ROUTES = {
},
SETTINGS_2FA: {
route: 'settings/security/two-factor-auth',
getRoute: (backTo?: string) => getUrlWithBackToParam('settings/security/two-factor-auth', backTo),
getRoute: (backTo?: string, forwardTo?: string) => getUrlWithBackToParam('settings/security/two-factor-auth', backTo, forwardTo),
},
SETTINGS_STATUS: 'settings/profile/status',

Expand Down

0 comments on commit fb58fad

Please sign in to comment.