/
page.tsx
70 lines (58 loc) · 1.76 KB
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use client";
import { useRef } from "react";
const docsOrigin = "http://localhost:3001";
const webOrigin = "http://localhost:3002";
const docsReceiverUrl = `${docsOrigin}/auth`;
const webReceiverUrl = `${webOrigin}/auth`;
export default function Page(): JSX.Element {
const docsIframeRef = useRef<HTMLIFrameElement>(null);
const webIframeRef = useRef<HTMLIFrameElement>(null);
const syncTenantNameWithServices = (tenantName: string) => {
docsIframeRef.current?.contentWindow?.postMessage(
{ tenantName },
docsOrigin
);
webIframeRef.current?.contentWindow?.postMessage({ tenantName }, webOrigin);
};
const logInToTenantA = () => {
syncTenantNameWithServices("tenant-a");
};
const logInToTenantB = () => {
syncTenantNameWithServices("tenant-b");
};
const logInToTenantC = () => {
syncTenantNameWithServices("tenant-c");
};
const logOut = () => {
syncTenantNameWithServices("");
};
return (
<main>
<h3>ログイン</h3>
<div style={{ display: "flex", flexDirection: "column", gap: "4px" }}>
<div>
<button onClick={logInToTenantA}>テナントAにログイン</button>
</div>
<div>
<button onClick={logInToTenantB}>テナントBにログイン</button>
</div>
<div>
<button onClick={logInToTenantC}>テナントCにログイン</button>
</div>
<div>
<button onClick={logOut}>ログアウト</button>
</div>
<iframe
src={docsReceiverUrl}
ref={docsIframeRef}
style={{ display: "none" }}
></iframe>
<iframe
src={webReceiverUrl}
ref={webIframeRef}
style={{ display: "none" }}
></iframe>
</div>
</main>
);
}