Comments (10)
It is working now, thank you sooo much ❤️
from hyper-express-session.
Yes, there is. You can store a boolean value like "logged_in" in your session and then check it on requests to determine if someone is logged in.
Simply put:
Start Session -> Check For Login Flag
from hyper-express-session.
"Error: SessionEngine: Session was not started. Please call Request.session.start() before calling Request.session.get()"
Can I have an example?
from hyper-express-session.
webserver.post('/api/login', async (request, response) => {
// Start the session
await request.session.start();
// Retrieve the flag or whatever property you use to specify if someone is logged in
const is_logged_in = request.session.get('logged_in') === true;
// Do stuff with is_logged_in
});
from hyper-express-session.
How do I retrieve the "is_logged_in" value in other files?
Like express-session.
from hyper-express-session.
is_logged_in is not a property by default.
webserver.post('/api/login', async (request, response) => {
// Assume you did validation and are ready to create their session, create it like below
// Start the session
await request.session.start();
// Store session data (This is where you would store a flag / propery like is_logged_in)
request.session.set({
is_logged_in: true,
account: 'something',
something: 'something else'
});
// Send the response as you normally would
});
// Assume this is a authenticated endpoint
webserver.get('/api/account', async (request, response) => {
// Start the session
await request.session.start();
// Retrieve the session data and check for is_logged_in property
const session = request.session.get();
if (session.is_logged_in) {
// Do stuff here and return the account info and stuff
}
});
from hyper-express-session.
When you fetch at /api/account while your logged in, it will remove all the session data because it starts the session again, which resets the session.
Any way to get around that?
from hyper-express-session.
No, starting a session just means the underlying session object is initialized with data. It should not reset your session. If your session is begin reset every time you start it then that means you haven't properly configured the session engine to work with your storage mechanism properly.
Please see the examples on https://github.com/kartikk221/hyper-express-session/blob/main/docs/Examples.md for a better idea of how to integrate hyper-express-session
from hyper-express-session.
Which Redis package are you using for https://github.com/kartikk221/hyper-express-session/blob/main/docs/Examples.md?
Cause the package I am using seems to have issues.
from hyper-express-session.
That example is based on https://github.com/luin/ioredis but the session engine should work with any database and any adapter as long as you properly reflect each of the engine's actions into your db
from hyper-express-session.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hyper-express-session.