From 71fd7155242b1629afc13be3cd5c90155c53a2ab Mon Sep 17 00:00:00 2001 From: Daniel Choudhury Date: Tue, 21 May 2024 21:21:58 +0700 Subject: [PATCH] Cleanup createStreamingHandler --- .../src/streaming/createReactStreamingHandler.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/streaming/createReactStreamingHandler.ts b/packages/vite/src/streaming/createReactStreamingHandler.ts index 096cd93d2723..40eeefa57417 100644 --- a/packages/vite/src/streaming/createReactStreamingHandler.ts +++ b/packages/vite/src/streaming/createReactStreamingHandler.ts @@ -6,6 +6,7 @@ import type { HTTPMethod } from 'find-my-way' import { createIsbotFromList, list as isbotList } from 'isbot' import type { ViteDevServer } from 'vite' +import type { ServerAuthState } from '@redwoodjs/auth' import { middlewareDefaultAuthProviderState } from '@redwoodjs/auth' import type { RouteSpec, RWRouteManifestItem } from '@redwoodjs/internal' import { getAppRouteHook, getConfig, getPaths } from '@redwoodjs/project-config' @@ -71,7 +72,14 @@ export const createReactStreamingHandler = async ( // @NOTE: we are returning a FetchAPI handler return async (req: Request) => { let mwResponse = MiddlewareResponse.next() - let decodedAuthState = middlewareDefaultAuthProviderState + + // Default auth state + let decodedAuthState: ServerAuthState = { + ...middlewareDefaultAuthProviderState, + cookieHeader: req.headers.get('cookie'), + roles: [], + } + // @TODO: Make the currentRoute 404? let currentRoute: RWRouteManifestItem | undefined let parsedParams: any = {} @@ -188,11 +196,7 @@ export const createReactStreamingHandler = async ( cssLinks, isProd, jsBundles, - authState: { - roles: [], - cookieHeader: req.headers.get('cookie'), - ...decodedAuthState, - }, + authState: decodedAuthState, }, { waitForAllReady: isSeoCrawler,