JavaScriptServices icon indicating copy to clipboard operation
JavaScriptServices copied to clipboard

Pre render send cookies

Open jeinz11 opened this issue 9 years ago • 3 comments

Hi just wondering if there is a way to send the cookie during SSR. i notice that in the first run all cookies and identities are empty

is there a way to specify the cookie in this method

        var prerenderResult = await Prerenderer.RenderToString(
            "/",
            nodeServices,
            new JavaScriptModuleExport(applicationBasePath + "/ClientApp/dist/boot-server"),
            unencodedAbsoluteUrl,
            unencodedPathAndQuery,
            transferData,
            30000
        );

jeinz11 avatar May 28 '17 05:05 jeinz11

@SteveSandersonMS , @laskoviymishka please help i just want to send my cookie during SSR im using asp.net core cookie authentication middleware thanks for helping

jeinz11 avatar May 29 '17 10:05 jeinz11

I think you can unpack the cookie data and pass it in transferData. It arrives in boot-server in params.data

Maarten88 avatar May 30 '17 23:05 Maarten88

Yes, @Maarten88 is correct. The docs at https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.SpaServices under Passing data from .NET code into JavaScript code give a specific example of passing cookies to the boot-server.ts file. From there, it's up to you to pass it to the rest of your app in whatever way you want, using the APIs provided by your chosen SPA framework, and from there you can include it in your fetch requests if you want.

SteveSandersonMS avatar Jun 05 '17 10:06 SteveSandersonMS