Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Existing Code not working with Couchbase 5.0 #18

Open
naikabhay opened this issue Mar 7, 2018 · 10 comments
Open

Existing Code not working with Couchbase 5.0 #18

naikabhay opened this issue Mar 7, 2018 · 10 comments

Comments

@naikabhay
Copy link

naikabhay commented Mar 7, 2018

Hi All,

The code is not up to date for Couchbase version 5.0, As you all are aware that couchbase has changed the authentication code in latest version. So this code needs to be updated for latest version

@waffledonkey
Copy link

While I agree it should probably be updated the module has no specific couchbase version dependency so it would have to test to see if authenticate was a valid method of the cluster object and if so call that with a provided username/password otherwise not... and then it'd have to confirm that username and password were provided or maybe default them to the bucket name but that seems terrible...

I think your best bet is to use the db property and auth/open the bucket externally.

const couchbase = require('couchbase');
const ms        = require('ms');
const session   = require('express-session');
const store     = require('connect-couchbase');

var bucket;
var cluster = new couchbase.Cluster('couchbase://127.0.0.1?detailed_errcodes=1');

cluster.authenticate($USERNAME, $PASSWORD);
bucket = cluster.openBucket($BUCKET);                       <<<<<<<<<<<<<<<<<<<<<<

// NOTE: session.cookie.maxAge wants milliseconds, session.store.ttl wants seconds
app.use(session({
    cookie: {
        httpOnly: true,
        maxAge: ms($LIFETIME),
        secure: $BOOL; as appropriate
    },
    name: something that doesn't scream "I'm using express",
    resave: $BOOL; as appropriate,
    rolling: $BOOL; as appropriate,
    saveUninitialized: $BOOL; as appropriate,
    secret: $SECRET
    store: new Store({
        db: bucket  -OR-  cluster.openBucket($BUCKET)      <<<<<<<<<<<<<<<<<<<<<<
        ttl: ms($LIFETIME) / 1e3,
        prefix: as appropriate
    }).on('disconnect', function () {
        // how important is it to your app that the session store is available?
    });
});

@dalborgo
Copy link

dalborgo commented Oct 3, 2018

It doesn't work anymore with the last npm couchbase module (2.6.0).

@waffledonkey
Copy link

Could you add an error message or description of the behavior? Does simply holding back the couchbase module still work or is it something else that is causing it not to work?

FWIW I'm not the maintainer of this project -- nor do I care to be -- I just thought the previous bug was a bit disingenuous; at the time. It may very well be that the module does not work with the latest SDK. That would be unfortunate, but not unexpected as the couchbase SDK is very volatile and even their own things (ottoman for example) don't work with the latest version or you have to go to some lengths to get it to work. In theory there's an Ottoman 2 but no one knows where it is or when it will be released or if released whether it will be compatible with the current SDK... I love couchbase, but it's a mess.

@dalborgo
Copy link

dalborgo commented Oct 4, 2018

Thank you, waffledonkey.

With the couchbase sdk 2.5.1, your above example works perfectly. With the 2.6.0 I get the "cannot perform operations on a shutdown bucket" error when I instance the store with the "new Store" line.
It seems to be an authentication problem. I agree with you about the SDK volatility...

Thank you again for your answer.

@waffledonkey
Copy link

waffledonkey commented Oct 4, 2018 via email

@dalborgo
Copy link

dalborgo commented Oct 24, 2018

My fault. With the couchbase 2.6.0 dependency my previous couchbase user (a read only user admin) doesn't work anymore. Righlty, a read only admin can't perform operation (for example write a doc) on the bucket. With the 2.5.1 instead you can do that with it. Changing the user's permission everything works properly.

@waffledonkey
Copy link

Hey @dalborgo have you tried with @2.6.2 or do you have an example of the code you used with 2.6? my previous implementation is no longer working and it doesn't appear to be related to credentials/role.

@dalborgo
Copy link

dalborgo commented Jan 28, 2019

See the attachment
server.zip

I use the bucket connect event otherwise I get a "shoutdown bucket error" when i set the store.
bucket.on('connect', () => { ... })

@waffledonkey
Copy link

You're good people. :)

I see you wrapped the whole server start in the event emitter... interesting. In my case it seems to work fine if I define the Store outside of mounting the middleware (similar to what you did) and if I hack on the module to add authentication, update the openBucket method signature and stop trying to set connection and operation timeout (basically, all the existing pull requests).

If, however, I try to pass it an existing bucket instance using the db option it doesn't work, thus why I asked.

I think we need to get the pull requests merged or someone needs to fork/takeover this project. How do you like Ottoman? Have you looked at Lounge? (it's more Mongoose-like)

@dalborgo
Copy link

I did not know Lounge! It is very interesting and more updated than Ottoman. Thank you for the advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants