Cookie sometimes contains more than one value

This commit is contained in:
FrankRua 2022-04-14 11:46:17 -04:00
parent 086be1ab6b
commit b28f03d76c

View file

@ -57,9 +57,16 @@ export function getCookieDomainValue() {
Returns empty string if cookie not found or "did" string not present.
*/
export function getDeviceIdValue(){
const cookieValue = getCookieByName(cookieNames.DXDEV);
const cookieValueMatch = cookieValue.match("(?<=did=).*?(?=&)");
// Sometimes these cookie contains more than the device ID.
const cookieValue = getCookieValueByName(cookieNames.DXDEV);
const cookieValuesSplit = cookieValue.split('=');
// If this is the only value, just use that.
if(cookieValuesSplit.length === 2){
return cookieValuesSplit[1];
}
const cookieValueMatch = cookieValue.match("(?<=did=).*?(?=&)");
if(cookieValueMatch){
return cookieValueMatch[0];
}
@ -71,7 +78,7 @@ export function getDeviceIdValue(){
Gets value of sid cookie, returns empty string if not found.
*/
export function getSessionIdValue(){
const cookieValue = getCookieByName(cookieNames.SESSION_ID);
const cookieValue = getCookieValueByName(cookieNames.SESSION_ID);
if(cookieValue){
return cookieValue;
@ -84,7 +91,7 @@ export function getSessionIdValue(){
Gets value of skey cookie, returns 0 if not found.
*/
export function getSessionKeyValue(){
const cookieValue = getCookieByName(cookieNames.SESSION_KEY);
const cookieValue = getCookieValueByName(cookieNames.SESSION_KEY);
if(cookieValue){
return cookieValue;
@ -140,7 +147,7 @@ function getDomainWithoutSubdomain() {
/*
Gets cookie value by name, returns empty string if not found.
*/
function getCookieByName(name) {
function getCookieValueByName(name) {
const value = "; " + document.cookie;
const parts = value.split("; " + name + "=");