demos for spacedust
1import { useRef, useEffect } from 'react';
2
3export function WhoAmI({ onIdentify, origin }) {
4 const frameRef = useRef(null);
5
6 useEffect(() => {
7 function handleMessage(ev) {
8 if (
9 ev.source !== frameRef.current?.contentWindow ||
10 ev.origin !== origin
11 ) return;
12 onIdentify(ev.data);
13 }
14 window.addEventListener('message', handleMessage);
15 return () => window.removeEventListener('message', handleMessage);
16 }, []);
17
18 return (
19 <iframe
20 src={`${origin}/prompt?app=notifications.microcosm.blue`}
21 referrerPolicy="strict-origin"
22 ref={frameRef}
23 height="180"
24 width="360"
25 style={{
26 border: 'none',
27 display: 'block',
28 colorScheme: 'none',
29 margin: '0 auto',
30 }}
31 >
32 Ooops, failed to load the login helper
33 </iframe>
34 );
35}