hapijs / nes

WebSocket adapter plugin for hapi routes
Other
502 stars 87 forks source link

Error: Connection requires authentication #297

Closed kirbyjs closed 4 years ago

kirbyjs commented 4 years ago

Support plan

Context

What are you trying to achieve or the steps to reproduce?

Currently, I'm trying to add a pub/sub with @hapi/nes with cookie authentication. In production my app is using @hapi/hapi and @hapi/cookie to authenticate our REST endpoints.

This is the server code that I added:


server.register({
    plugin: Nes.plugin,
    options: {
        auth: {
            type: 'cookie',
            isSecure: config.isSecure,
            isSameSite: 'Lax'
        }
    }
});
server.subscription('/some-subscribe-endpoint');
await server.start();

This is the browser client code that I added:

import Nes from '@hapi/nes/lib/client';

const {host, protocol} = window.location;
const connectionUrl = (protocol === 'https:') ? `wss://${host}/` : `ws://${host}/`;
const client = new Nes.Client(connectionUrl);

fetch('/nes/auth', {credentials: 'same-origin'})
    .then(() => client.connect({delay: 2000, retries: 3}))
    .then(() => {
        client.subscribe(`/some-subscribe-endpoint`, (data) => {
            // do something
        });
    });

The nes/auth endpoint returns {"status":"authenticated"}, but I did see that the returned cookie size was massive:

image

I'm not sure if that has anything to do with it or not. I also played around with the password, but that didn't really affect the size of the cookie.

I also tested in Chrome, Firefox and Safari, and all of them had the same result.

What was the result you got?

Error: Connection requires authentication

What result did you expect?

No authentication issue.

hueniverse commented 4 years ago

Unfortunately, no community resources were available to help resolve this issue after two weeks, and it is being closed. We close unresolved community issues to keep the issue tracker organized and effective. Please check https://hapi.dev/support for other support options.