GithubHelp home page GithubHelp logo

kartikk221 / hyper-express-session Goto Github PK

View Code? Open in Web Editor NEW
15.0 15.0 6.0 58 KB

Middleware that Implements high performance cookie based sessions into the HyperExpress webserver.

License: MIT License

JavaScript 100.00%

hyper-express-session's People

Contributors

imlunahey avatar kartikk221 avatar tripodsgames avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hyper-express-session's Issues

Session closes after user gets redirected from another site.

I have a setup where the user goes to /core/discord/login and the referral in query strings gets saved in sessions then gets redirected to discord oauth2

After user gets redirected to callback path, the session destroys itself.

I suppose this is because the user got redirected from another site.
Any way to fix this?

Small issues with the documentation

Hi There. I noticed a couple of issues in the documentation:

in hyper-express-session/docs/Examples.md:

const SessionEngine = require('hyper-express-session');
const TestEngine = new session_engine({

that should be:

const SessionEngine = require('hyper-express-session');
const TestEngine = new TestEngine({

also it seems that in same example:

TestEngine.on('destroy', async (session) => {
    return await redis.del('session:' + session.id);
});

but it appears that on is not a method for SessionEngine:

file:///Users/jason/NodeProjects/BaaS/hyper-express/Authentication/SessionHandling.js:43
TestEngine.on('destroy', async (session) => {
           ^

TypeError: TestEngine.on is not a function
    at file:///Users/jason/NodeProjects/BaaS/hyper-express/Authentication/SessionHandling.js:43:12
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)
[nodemon] app crashed - waiting for file changes before starting...

TestEngine not of type string

const webserver = new HyperExpress.Server();
webserver.use(TestEngine)

Argument of type 'SessionEngine' is not assignable to parameter of type 'string'.ts(2769)

setSessionEngine does not exist on type server

typescript support?

Hey there,

Thanks for hyper-express! I was wondering if you could add typescript support for this module?

Thanks!
Jason

Touch event with memcached

I store sessions in memcached with this code

const SessionEngine = require('hyper-express-session');
const Memcached = require('memcached');
const memcached = new Memcached('memcached:11211');

const TOKEN_EXPIRE = 60 * 45; // Default duration is 45 Minutes

const sessionEngine = new SessionEngine({
    duration: 1000 * TOKEN_EXPIRE,
    cookie: {
        name: 'my_session',
        path: '/',
        httpOnly: true,
        secure: true,
        sameSite: 'strict',
        secret: '-------------------'
    }
});

const getMemcached = key => new Promise((resolve, reject) => memcached.get(key, (err, data) => {
    if(err) reject(); else resolve(data);
}));

sessionEngine.use('read', async session => await getMemcached(session.id));
sessionEngine.use('touch', session => memcached.touch(session.id, ?????????????, err => console.error(err)));
sessionEngine.use('write', session => memcached.set(session.id, session.get(), TOKEN_EXPIRE, err => console.error(err)));
sessionEngine.use('destroy', session => memcached.del(session.id, err => console.error(err)));

module.exports = sessionEngine

What value for the "expiry timestamp" is icorrect to use with "touch" event?

P.S. Memcached time is in seconds

Better typescript support?

Thanks for the initial Typescript support. ๐Ÿ’–
Just tried one of the examples and my IDE isn't liking it. ๐Ÿ˜ž

image

This is from webserver.use(sessionStore);

I also get an issue with request.session not being typed.
image

request.session.signed_id in undefined

Server.get('/auth/login', async (request, response) => {

    await request.session.start();

    await request.session.set({
        myid: 'some_id',
        visits: 0,
    });

    console.log('request.session.id', request.session.id)
    console.log('request.session.signed_id', request.session.signed_id) // <-------------- undefined

    return response.json({
        token: request.session.signed_id
    });
});

Ubuntu / Node 18.1.0

P.S. At local machine (OSX) everything is working and "signed_id" is present

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.