feat(rn,auth) add support for toekn URL auth

This commit is contained in:
Saúl Ibarra Corretgé
2023-08-15 11:46:45 +02:00
committed by Saúl Ibarra Corretgé
parent c19d91a373
commit dca40dc6cb
9 changed files with 130 additions and 53 deletions

View File

@@ -631,3 +631,29 @@ export function appendURLParam(url: string, name: string, value: string) {
return newUrl.toString();
}
/**
* Adds new hash param to a url string.
* Checks whether to use '?' or '&' as a separator (checks for already existing params).
*
* @param {string} url - The url to modify.
* @param {string} name - The param name to add.
* @param {string} value - The value for the param.
*
* @returns {string} - The modified url.
*/
export function appendURLHashParam(url: string, name: string, value: string) {
const newUrl = new URL(url);
const dummyUrl = new URL('https://example.com');
// Copy current hash-parameters without the '#' as search-parameters.
dummyUrl.search = newUrl.hash.substring(1);
// Set or update value with the searchParams-API.
dummyUrl.searchParams.append(name, value);
// Write back as hash parameters.
newUrl.hash = dummyUrl.searchParams.toString();
return newUrl.toString();
}