-
Notifications
You must be signed in to change notification settings - Fork 4
Commerce: Universal cart cookie across all LUX sites #163
Copy link
Copy link
Open
Labels
Description
The goal: have the cart which is the same on all LUX sites
- Using cross domain communication set cart cookie or local storage on all lux domains after user interacts with the cart
<!-- parent.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Parent Frame</title>
</head>
<body>
<h1>Parent Frame</h1>
<iframe id="childFrame" src="https://child.example.com"></iframe>
<script>
// Simulate obtaining the JWT token
const jwtToken = "sample_jwt_token";
// Send the JWT token to the child frame
window.addEventListener('load', function() {
const childFrame = document.getElementById('childFrame');
childFrame.contentWindow.postMessage(jwtToken, 'https://child.example.com');
});
</script>
</body>
</html><!-- child.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Child Frame</title>
</head>
<body>
<h1>Child Frame</h1>
<script>
// Listen for messages from the parent frame
window.addEventListener('message', function(event) {
// Check if the message is from a trusted origin
if (event.origin === 'https://parent.example.com') {
// Set the JWT token received from the parent frame
const jwtToken = event.data;
localStorage.setItem('token', jwtToken);
console.log("JWT token set:", jwtToken);
} else {
console.warn("Received message from untrusted origin:", event.origin);
}
});
</script>
</body>
</html>Reactions are currently unavailable