Code Explanation
Code Explanation:
- Module in package.json with cross-domain-storage to exchange tokens between the two websites:
"dependencies": {
...
"amazon-cognito-identity-js": "^5.2.9",
"cross-domain-storage": "^2.0.7",
...
}

- The signOut function to invalidate all tokens provided by Cognito in case the user logs out:
export function signOut(callbacks: { onSuccess: (msg: string) => void; onFailure: (err: Error) => void }) {
if (currentUser) {
//currentUser.signOut()
currentUser.globalSignOut(callbacks)
}
}

- Handle session token from web1 to web2 in case of logging in at web1 and the token will be set for web2 with the allowed origin on web2 in signIn.ts of web1:
const handleSendToken = () => {
// send token
if(!localStorage) return
var tokenStorage = createGuest('http://localhost:3001/accessStorage');
Object.keys(localStorage).forEach(key => {
console.log('key', key);
tokenStorage.set(key, localStorage[key])
})
}

- Allow the origin on web2 to accept access from web1 in App.tsx:
const App: React.FunctionComponent = () => {
useEffect(() => {
createHost([
{
origin: "http://localhost:3000",
allowedMethods: ["set", "remove"],
},
]);
}, []);
}
