Skip to content

PROD | WEB91-202 | signup cookies handling#1077

Open
isha-dubey wants to merge 4 commits intomainfrom
isha/web91-202-signup-cookies-handling
Open

PROD | WEB91-202 | signup cookies handling#1077
isha-dubey wants to merge 4 commits intomainfrom
isha/web91-202-signup-cookies-handling

Conversation

@isha-dubey
Copy link
Collaborator

No description provided.

Copy link

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other comments (5)
  • src/components/signupComp/SignUp.js (82-92) Consider using URLSearchParams for building the redirect URL to ensure all parameters are properly encoded and the URL is constructed correctly:
    let redirectUrl = SUCCESS_REDIRECTION_URL?.replace(':session', payload.session);
    const urlParams = new URLSearchParams();
    const signupDate = getCookie('signup_date');
    const interestedServices = getCookie('interested_services');
    
    if (signupDate) urlParams.append('signup_date', signupDate);
    if (interestedServices) urlParams.append('interested_services', interestedServices);
    
    Object.entries(getUtmFromCookies()).forEach(([key, value]) => {
        if (key?.startsWith('utm_') && value) urlParams.append(key, value);
    });
    
    const queryString = urlParams.toString();
    if (queryString) redirectUrl += `&${queryString}`;
    
    location.href = redirectUrl;
    
  • src/components/signupComp/SignUp.js (60-62) When setting UTM parameter cookies on lines 60-62, consider checking if they already exist to avoid overwriting values that might have been set earlier in the user journey:
    const urlParams = new URLSearchParams(window.location.search);
    urlParams.forEach((value, key) => {
        if (key.startsWith('utm_') && !getCookie(key)) setSharedCookie(key, value, 30);
    });
    
  • src/utils/utilis.js (63-81) There are now two cookie-setting functions (`setCookie` and `setSharedCookie`) with different implementations and security settings. Consider consolidating these functions or clearly documenting when to use each one to avoid confusion and ensure consistent cookie handling across the application.
  • src/components/signupComp/StepThree/StepThree.js (299-299) The cookie expiration is hardcoded to 30 days in multiple places. Consider defining this as a constant at the top of the file or importing it from a configuration file to ensure consistency across all cookie operations.
  • src/utils/utilis.js (63-63) In `setSharedCookie()`, the cookie value is properly encoded, but the cookie name isn't checked for special characters. While this might not be an immediate issue with your current usage, it's a good practice to ensure cookie names are valid to prevent future bugs.

💡 To request another review, post a new comment with "/windsurf-review".

Comment on lines +82 to +92
let redirectUrl = SUCCESS_REDIRECTION_URL?.replace(':session', payload.session);
const signupDate = getCookie('signup_date');
const interestedServices = getCookie('interested_services');
if (signupDate) redirectUrl += `&signup_date=${encodeURIComponent(signupDate)}`;
if (interestedServices)
redirectUrl += `&interested_services=${encodeURIComponent(interestedServices)}`;
Object.entries(getUtmFromCookies()).forEach(([key, value]) => {
if (key?.startsWith('utm_') && value)
redirectUrl += `&${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
});
location.href = redirectUrl;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's duplicate code for building the redirect URL with parameters in three different places (lines 82-92, 393-406, and 490-503). Consider extracting this into a reusable function to improve maintainability and reduce the risk of inconsistent behavior.

Comment on lines +520 to +524
setSharedCookie(
'interested_services',
JSON.stringify(value.map((obj) => obj.label)),
30
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error handling around the JSON.stringify operation to prevent potential issues if the data structure changes in the future.

Suggested change
setSharedCookie(
'interested_services',
JSON.stringify(value.map((obj) => obj.label)),
30
);
setSharedCookie(
'interested_services',
try {
JSON.stringify(value.map((obj) => obj.label))
} catch (e) {
console.error('Error stringifying services:', e);
'[]'
},
30
);

Comment on lines +56 to +59
document.cookie.split(';').forEach((cookie) => {
const [key, value] = cookie.trim().split('=');
if (key?.startsWith('utm_') && value) result[key] = decodeURIComponent(value);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cookie parsing in getUtmFromCookies() might fail if there's a malformed cookie without an equals sign. Consider adding a check before destructuring:

Suggested change
document.cookie.split(';').forEach((cookie) => {
const [key, value] = cookie.trim().split('=');
if (key?.startsWith('utm_') && value) result[key] = decodeURIComponent(value);
});
document.cookie.split(';').forEach((cookie) => {
const parts = cookie.trim().split('=');
if (parts.length >= 2) {
const [key, ...valueParts] = parts;
const value = valueParts.join('='); // Handle values that might contain '='
if (key?.startsWith('utm_') && value) result[key] = decodeURIComponent(value);
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant