www.avinashdalvi.com | www.internetkatta.com
@aviboy2006
Hello Am Avinash - @aviboy2006
Call me "Avi"
Software Engineer II @Eagleview India
AWS Community Builder | Open Source Enthusiast
What is AWS Amplify ?
What AWS Amplify provides ?
Host static website on AWS Amplify
How to keep environment variable secured ?
Demo
Discussion (Q/A)
www.avinashdalvi.com | www.internetkatta.com
@aviboy2006
When two domain share same resources like one is www.example.com and one is customer.example.com
Two domain rights with same owner or accessible
Avoid multiple times resource access or fetch if it duplicate across two subdomain or cross domain
Major use case is when login to one domain and access to all subdomains
www.avinashdalvi.com | www.internetkatta.com
@aviboy2006
Sending Data
Receiving Data
www.example.com
abc.example.com
Sending Data
Receiving Data
www.avinashdalvi.com | www.internetkatta.com
@aviboy2006
HTML Code
function postCrossDomainMessage(msg) {
var win = document.getElementById('ifr').contentWindow;
win.postMessage(msg, "http://example.com/");
}
var postMsg = {"login": "user"}; // this is just example
postCrossDomainMessage(postMsg);
<iframe style="display:none;" src="http://example.com/getlocalstorage.html" id="ifr"></iframe>
Javascript Code
www.avinashdalvi.com | www.internetkatta.com
@aviboy2006
var PERMITTED_DOMAIN = "http://example.com";
/**
* Receiving message from other domain
*/
window.addEventListener('message', function(event) {
if (event.origin === PERMITTED_DOMAIN) {
//var msg = JSON.parse(event.data);
// var msgKey = Object.keys(msg)[0];
if (event.data) {
localStorage.setItem("localstorage", event.data);
} else {
localStorage.removeItem("localstorage");
}
}
});
www.avinashdalvi.com | www.internetkatta.com
@aviboy2006
Two Angular apps share their login data between them using pub-sub pattern
www.avinashdalvi.com | www.internetkatta.com
@aviboy2006
www.avinashdalvi.com | www.internetkatta.com
@aviboy2006
https://www.internetkatta.com/share-cookies-or-local-storage-data-between-cross-domain
https://github.com/aviboy2006/cross-domain-cookie-sharing
https://github.com/aviboy2006/cookie-or-localstorage-sharing-in-angular-apps
https://en.wikipedia.org/wiki/HTTP_cookie
https://www.w3schools.com/jsref/prop_win_localstorage.asp
www.avinashdalvi.com | www.internetkatta.com
@aviboy2006
You can reach out to me here 👇🏻
@aviboy2006
@aviboy2006
https://www.linkedin.com/in/avinash-dalvi-315b021a/
avinashsdalvi@gmail.com
avinashdalvi.com | www.internetkatta.com