forked from mosip/esignet-signup
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User preferred selected language is not retained during redirection o…
…r when user navigates back post perform action suggested on the popup Signed-off-by: Sreang Rathanak <[email protected]>
- Loading branch information
Sreang Rathanak
committed
Jul 10, 2024
1 parent
c2be525
commit 7d2eb68
Showing
3 changed files
with
42 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,39 @@ | ||
import { Buffer } from "buffer"; | ||
|
||
export const getSignInRedirectURL = (redirectUrl: string | undefined, hash: string, defaultPath: string): string => { | ||
export const getSignInRedirectURL = ( | ||
redirectUrl: string | undefined, | ||
hash: string, | ||
defaultPath: string | ||
): string => { | ||
const locale = localStorage.getItem("esignet-signup-language"); | ||
if (!!hash) { | ||
const signInQueryParams = Buffer.from(hash ?? "", "base64")?.toString(); | ||
return redirectUrl + "?" + signInQueryParams; | ||
const signInQueryParams = replaceUILocales(hash, locale); | ||
return redirectUrl + "?" + signInQueryParams.toString(); | ||
} | ||
return defaultPath + "?ui_locales=" + locale; | ||
}; | ||
|
||
export const replaceUILocales = ( | ||
hash: string, | ||
locale: string | null | ||
): URLSearchParams => { | ||
// Convert the decoded string to JSON | ||
const decodedBase64 = atob(hash.substring(1)); | ||
|
||
var urlSearchParams = new URLSearchParams(decodedBase64); | ||
|
||
// Convert the decoded string to JSON | ||
var jsonObject: Record<string, string> = {}; | ||
urlSearchParams.forEach(function (value, key) { | ||
jsonObject[key] = value; | ||
// Assign the current i18n language to the ui_locales | ||
if (key === "ui_locales") { | ||
jsonObject[key] = locale || value; | ||
} | ||
}); | ||
|
||
// Convert the JSON back to decoded string | ||
Object.entries(jsonObject).forEach(([key, value]) => { | ||
urlSearchParams.set(key, value); | ||
}); | ||
|
||
return defaultPath; | ||
return urlSearchParams; | ||
}; |