diff --git a/keyserver/src/responders/landing-handler.js b/keyserver/src/responders/landing-handler.js --- a/keyserver/src/responders/landing-handler.js +++ b/keyserver/src/responders/landing-handler.js @@ -103,6 +103,7 @@ const { renderToNodeStream } = ReactDOMServer; async function landingResponder(req: $Request, res: $Response) { + const siweNonce = req.header('siwe-nonce'); const [{ jsURL, fontURLs, cssInclude }, LandingSSR] = await Promise.all([ getAssetInfo(), getWebpackCompiledRootComponentForSSR(), @@ -159,14 +160,20 @@ const routerBasename = basePath.replace(/\/$/, ''); const clientPath = routerBasename + req.url; const reactStream = renderToNodeStream( - , + , ); reactStream.pipe(res, { end: false }); await waitForStream(reactStream); + const siweNonceString = siweNonce ? `"${siweNonce}"` : 'null'; // prettier-ignore res.end(html` + diff --git a/landing/landing-ssr.react.js b/landing/landing-ssr.react.js --- a/landing/landing-ssr.react.js +++ b/landing/landing-ssr.react.js @@ -4,17 +4,28 @@ import { StaticRouter } from 'react-router'; import Landing from './landing.react'; +import { SIWENonceContext } from './siwe-nonce-context'; export type LandingSSRProps = { +url: string, +basename: string, + +siweNonce: ?string, }; function LandingSSR(props: LandingSSRProps): React.Node { - const { url, basename } = props; + const { url, basename, siweNonce } = props; + + const siweNonceContextValue = React.useMemo( + () => ({ + siweNonce, + }), + [siweNonce], + ); const routerContext = React.useMemo(() => ({}), []); return ( - + + + ); } diff --git a/landing/root.js b/landing/root.js --- a/landing/root.js +++ b/landing/root.js @@ -4,13 +4,23 @@ import { BrowserRouter } from 'react-router-dom'; import Landing from './landing.react'; +import { SIWENonceContext } from './siwe-nonce-context.js'; declare var routerBasename: string; +declare var siweNonce: ?string; function RootComponent(): React.Node { + const siweNonceContextValue = React.useMemo( + () => ({ + siweNonce, + }), + [], + ); return ( - + + + ); }