Giter Site home page Giter Site logo

Cookie expiration bug about couchdb-nano HOT 6 CLOSED

glynnbird avatar glynnbird commented on June 8, 2024
Cookie expiration bug

from couchdb-nano.

Comments (6)

glynnbird avatar glynnbird commented on June 8, 2024

Fixed in 10.1.2

from couchdb-nano.

YakovL avatar YakovL commented on June 8, 2024

Hey @glynnbird , thanks for the fix! However, I've figured that for me the source of the issue is different (I've updated to 10.1.2). It looks like the auth is "forgotten" after I hybernate my laptop and then wake it up again. Sure, this is not a big issue for production as servers are not hibernated normally (I guess), but still this looks like a buggy behavior. Should I create a new issue for this?

from couchdb-nano.

glynnbird avatar glynnbird commented on June 8, 2024

from couchdb-nano.

YakovL avatar YakovL commented on June 8, 2024

Right, I see. I'm thinking about a way to make sure we're authorized before each request

private get authedClientPromise(): Promise<nanoClient.ServerScope> {
    return (async () => {
        // TODO: check if we are authed
        // TODO: if not, do this.client.auth(...)
        return this.client
    })()
}

Could you suggested a proper way to do the "is authed" check? I understand that we can send a request, check if we got 401 and try to reauth in that case, but doing this in each method is very WET (although better in terms of performance: the "is authed" check is an additional request).

May be it's possible to check the cookie expiration without a request? I'm not finding a dedicated method for this.

from couchdb-nano.

glynnbird avatar glynnbird commented on June 8, 2024

@YakovL

You can call:

const doc = await nano.session()

which will tell you if you're logged in or not, and if you are, what permissions you have.

from couchdb-nano.

YakovL avatar YakovL commented on June 8, 2024

Great, thanks, currently I'm using something like this

const session = await nano.session()

// 'cookie' when we're good and undefined otherwise
const isAuthed = session.info.authenticated

if(!isAuthed) await nano.auth(user, password)

and it works fine, although this doubles the number of requests to db.

from couchdb-nano.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.