Skip to content

Commit

Permalink
fix: updated II login process so that it doesnt listen to MM (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
alenmestrov authored Jan 15, 2025
1 parent 320e0b3 commit f8873d8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions node-ui/src/hooks/useIcp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,17 @@ export function useIcp(): useIcpReturn {
// Wait for II to say it's ready
const readyPromise = new Promise<MessageEvent>((resolve, reject) => {
const readyHandler = (e: MessageEvent) => {
window.removeEventListener('message', readyHandler);
if (e.origin !== iiUrl.origin || e.data.kind !== 'authorize-ready') {
win.close();
reject(new Error('Bad message from II window. Please try again.'));
} else {
resolve(e);
// Only process messages from II
if (e.origin !== iiUrl.origin) {
return; // Ignore messages from other origins
}

if (e.data?.kind !== 'authorize-ready') {
return; // Ignore messages with wrong kind
}

window.removeEventListener('message', readyHandler);
resolve(e);
};
window.addEventListener('message', readyHandler);
});
Expand Down

0 comments on commit f8873d8

Please sign in to comment.