( url: string | undefined | null, normalize: typeof normalizeParams )
| 97 | } |
| 98 | |
| 99 | function getParamsFromUrl( |
| 100 | url: string | undefined | null, |
| 101 | normalize: typeof normalizeParams |
| 102 | ) { |
| 103 | // since we do not always redirect the user back to the page they were on |
| 104 | // we need client locale and origin to construct the redirect url. |
| 105 | let returnUrl; |
| 106 | try { |
| 107 | returnUrl = new URL(url ? url : HOME_LOCATION); |
| 108 | } catch (_e) { |
| 109 | returnUrl = new URL(HOME_LOCATION); |
| 110 | } |
| 111 | |
| 112 | const origin = returnUrl.origin; |
| 113 | // if this is not one of the client languages, validation will convert |
| 114 | // this to '' before it is used. |
| 115 | const pathPrefix = returnUrl.pathname.split('/')[1] ?? ''; |
| 116 | return normalize({ |
| 117 | // strip off any query parameters |
| 118 | returnTo: returnUrl.origin + returnUrl.pathname, |
| 119 | origin, |
| 120 | pathPrefix |
| 121 | }); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Get the redirect parameters. |
no test coverage detected