aboutsummaryrefslogtreecommitdiff
path: root/vnext/server
diff options
context:
space:
mode:
Diffstat (limited to 'vnext/server')
-rw-r--r--vnext/server/middleware/renderer.js25
1 files changed, 19 insertions, 6 deletions
diff --git a/vnext/server/middleware/renderer.js b/vnext/server/middleware/renderer.js
index ae2600a7..bcecf760 100644
--- a/vnext/server/middleware/renderer.js
+++ b/vnext/server/middleware/renderer.js
@@ -11,6 +11,8 @@ import { VisitorProvider } from '../../src/ui/VisitorContext'
import path from 'path'
import fs from 'fs'
+import { me } from '../../src/api'
+import { HelmetProvider } from 'react-helmet-async'
const STATIC_ROOT = config.get('service.static_root') || path.resolve(__dirname, 'public')
@@ -22,6 +24,15 @@ const serverRenderer = async (req, res) => {
// links
const cookies = cookie.parse(req.headers.cookie || '')
+
+ let visitor
+
+ try {
+ visitor = await me()
+ } catch(e) {
+ console.log('Unauthenticated')
+ }
+
const links = await getLinks(req.originalUrl, cookies['sape_cookie'])
fs.readFile(filePath, 'utf8', (err, htmlData) => {
if (err) {
@@ -40,10 +51,12 @@ const serverRenderer = async (req, res) => {
const propsData = `<script>window.__PROPS__="${btoa(unescape(encodeURIComponent(JSON.stringify(props))))}";</script>${marker}`
let didError = false
const { pipe } = ReactDOMServer.renderToPipeableStream(
- <VisitorProvider>
- <StaticRouter location={req.baseUrl} context={routerContext}>
- <App {...props} />
- </StaticRouter>
+ <VisitorProvider auth={visitor}>
+ <HelmetProvider>
+ <StaticRouter location={req.baseUrl} context={routerContext}>
+ <App {...props} />
+ </StaticRouter>
+ </HelmetProvider>
</VisitorProvider>
, {
onShellReady() {
@@ -58,10 +71,10 @@ const serverRenderer = async (req, res) => {
res.statusCode = 500
res.setHeader('Content-type', 'text/html')
res.send(
- '<h1>Something went wrong :(</h1>'
+ '<h1>Something went wrong :(</h1>'
)
res.end()
- },
+ },
onAllReady() {
if (!didError) {
res.write(data[1])