Giter Site home page Giter Site logo

Comments (5)

tbenst avatar tbenst commented on May 18, 2024

I'm having a similar issue--unable to save the session when using a socket.io listener

Can read and write:

router.get('/count', ctx => {
    var session = ctx.session;
    session.count = session.count || 0;
    session.count++;
    ctx.body = session.count;
})

Can only read:

io.on('test', (ctx, data) => {
    console.log('test get count', ctx.session.count)
    var session = ctx.session;
    session.count = session.count || 0;
    session.count++;
})

from generic-session.

tbenst avatar tbenst commented on May 18, 2024

Edit: turns out this has a simple fix. The second fetch will work. Still looking for socket.io workaround

Just as a warning for others, it appears that koa-generic-session does not allow modification to session from a fetch call.

browser:

fetch('/count', {
    method: 'POST',
    headers: {
        count: 1,
    }
})
fetch('/count', {
    method: 'POST',
    headers: {
        count: 2,
    },
    credentials: 'include'
})

server:

router.post('/count', (ctx) => {
    var session = ctx.session
    console.log('sesh1', ctx.session)
    session.count = session.count || 0
    session.count = session.count + ctx.request.header.count
    console.log('sesh2', ctx.session)
    ctx.status = 200   
});

from generic-session.

hedgerh avatar hedgerh commented on May 18, 2024

im having the same read only issue in websockets while using koa-session and koa-websocket. tried switching to generic-session using a redis store and had the same issue.

@tbenst did you ever find a solution to this?

from generic-session.

tbenst avatar tbenst commented on May 18, 2024

@hedgerh haven't tried it yet but this appears to outline a solution: http://stackoverflow.com/questions/26643370/get-user-id-socket-io-passport-koa.

If you do try it, please do post if it works and/or the code, cheers!

Edit: also, if you only need to read this works: LnsooXD/koa-socket-session#1 (comment). May be able to modify this code for writing to session, haven't looked into it yet

from generic-session.

niftylettuce avatar niftylettuce commented on May 18, 2024

Closed per #94 (comment)

from generic-session.

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.