qubit icon indicating copy to clipboard operation
qubit copied to clipboard

Cannot use authentication and subscription

Open lucasavila00 opened this issue 1 year ago • 2 comments

If I use the authentication example and add subscription to it, the subscription doesn't work, as it reaches https://github.com/paritytech/jsonrpsee/blob/c9e26b04b1eb627e280657214ab7227f8d688267/server/src/middleware/rpc/layer/rpc_service.rs#L115 this line of code.

It seems that having any FromRequestExtensions usage in the router breaks subscriptions.

I was able to work around it by using 2 routers, one with HTTP and authentication, and the other WS and no authentication.

lucasavila00 avatar Aug 04 '24 23:08 lucasavila00

I'm afraid that I'm having trouble reproducing this, are you able to give a code example of a router where it happens?

I added the following handler:

#[handler(subscription)]
async fn my_sub(ctx: AuthCtx) -> impl Stream<Item = usize> {
    stream::iter([1, 2, 3])
}

#[tokio::main]
async fn main() {
    // Create the qubit router
    let router = Router::new()
        // ...
        .handler(my_sub);

    // ...
}

and tried using it from the authentication demo:

    api.my_sub.subscribe((n) => console.log("after sub", n));

and it works as expected, so long as the subscription is called after the user is authenticated with the cookie.

andogq avatar Aug 12 '24 13:08 andogq

I'm sorry for not posting the issue with the repro in the first place. I'll create one.

lucasavila00 avatar Aug 13 '24 02:08 lucasavila00

I'm going to close this issue out for now, but feel free to re-open if you're still facing this issue.

andogq avatar Dec 02 '24 07:12 andogq