kartikk221 / hyper-express-session Goto Github PK
View Code? Open in Web Editor NEWMiddleware that Implements high performance cookie based sessions into the HyperExpress webserver.
License: MIT License
Middleware that Implements high performance cookie based sessions into the HyperExpress webserver.
License: MIT License
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
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
There is no way to check if the user is logged in
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?
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
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...
Hey there,
Thanks for hyper-express! I was wondering if you could add typescript support for this module?
Thanks!
Jason
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.