Merge pull request #344 from Safelite/feature/CSR-394
Cookie sometimes contains more than one value
This commit is contained in:
commit
e5384bcd5f
1 changed files with 12 additions and 5 deletions
|
|
@ -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 && cookieValuesSplit[0] === 'did'){
|
||||
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 + "=");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue