fsbolero / Bolero

Bolero brings Blazor to F# developers with an easy to use Model-View-Update architecture, HTML combinators, hot reloaded templates, type-safe endpoints, advanced routing and remoting capabilities, and more.
https://fsbolero.io
Apache License 2.0
1.06k stars 53 forks source link

Force separate HTTP requests in "Server" mode #143

Open ittennull opened 4 years ago

ittennull commented 4 years ago

When Bolero works in "server" mode there is a websocket connection and whenever I define a service

type BookService =
    {
        signIn : string * string -> Async<option<string>>
    }
    interface IRemoteService with
        member this.BasePath = "/books"

the request is sent via this websocket. In "wasm" mode the same request is sent via regular HTTP request. How to force it to always use regular HTTP requests? I know I can create a HttpClient and do it myself but I'd like to use record types as in the example. The problem is that in "server" mode you can't set cookie in signIn: httpContext.SignInAsync(principal) throws InvalidOperationException("Headers are read-only, response has already started.") because it tries to modify headers of an ongoing response. Even the standard Bolero template doesn't work in "wasm" mode

OnurGumus commented 4 years ago

@ittennull better you should use json web tokens. Here's an example that works for both WASM and Non Wasm scenario: https://github.com/OnurGumus/FBlazorShop

I basically create a JWT and store it to cookie.

IMHO, The way of F# is stay away all this magical mambo jambo created by microsoft for authentication etc. because we simply don't need them.

ittennull commented 4 years ago

@OnurGumus thanks, I considered using JWT but cookie and built-in auth middleware seemed easier because I didn't need to add almost anything to the client, only server side. I will poke around a bit and maybe switch to JWT too.

Anyway it's still an issue that the standard bolero template doesn't work in server mode, not nice to newcomers

OnurGumus commented 4 years ago

It's the nature of web sockets. Even with blazor it's the same problem.

Tarmil commented 4 years ago

That being said, behind the scenes it uses SignalR, so maybe there's a way to force it to use long poll mode?