Comments (4)
- Does the session.reload() function saves after its execution just like doing session.reload() and session.save() ? (If yes I could optimize and fix a lot of bugs)
reload
loads the req.session
object with whatever value is in your store. It does not save the current session object.
I don't fully understand what your code is trying to accomplish, but this middleware automatically loads the session for you. So if you can try to change your code so you don't reload the session, that might be a general way to start eliminating bugs.
- Is there any like deep documentation of express-session which explains in detail what each function does ? (So I could know what issues my code has, and if some function already saves by themselves)
The README for this repo is most detailed documentation I know of.
The loading and saving of the session should generally "just work". The only time I've found myself needing to intervene in the loading and saving is when I modify the session inside a route that results in a redirect, which does not appear to be the case for you.
from session.
All right, thank you very much for your answers, everything’s clear now. I’ll look into fixing my code and clearing things up.
As for my code, I am trying to update the session each time someone makes a request to the website from a browser: check if the token is still valid (if not logout the user), if he is still in the database (if not, log him out to make him login back so it adds a valid entry).
The overall thing I’m trying to make with zero experience in sessions is a discord community website where there are accounts from Discord login, with a database to store account related data, and a lot of functionalities including an admin dashboard with statistics, ticket management, announcement creation, partnership management, account management (with different permissions and access following the user’s staffLevel variable).
So then partnerships are shown on a special page, announcements too and in the main page, etc..
Mostly a paid project one of my friends wants me to do to train myself and make him a good website (so you don’t punch me in the face for being that incompetent in a paid job xD)
That is a big project and I’m paid to do it, but it’s my first time making things that complex with sessions.
Anyways, you helped me on the issue I had, I am not going to bother you with the overall thing as I already know it’s horribly unoptimized and ugly.
Thank you so much for your time and help,
Adam.
from session.
@TheDogHusky I can't say for sure what the problem is, but it looks like your updateSession
function promise is calling session.reload, and session.save at the same time. If you want to reload the session here, you should probably wait to modify and save to the session until after the reload finishes.
something like:
export function updateSession(req: Request, res: Response, isDash?: boolean, redirectTo?: boolean): Promise<void|FlashMessage[]> {
return new Promise(async (resolve, reject) => {
await new Promise(function (resolve, reject) {
req.session.reload((err: Error) => {
if(err) {
console.log(err); // this might help debugging
updateSession(req, res, isDash, redirectTo).then(resolve).catch(reject);
} else {
resolve();
}
});
});
// now your session is reloaded...
from session.
I’ll try your solution out, thank you very much.
As I don’t know express-session a lot, I just have some little questions about this code:
- Does the session.reload() function saves after its execution just like doing session.reload() and session.save() ? (If yes I could optimize and fix a lot of bugs)
- Is there any like deep documentation of express-session which explains in detail what each function does ? (So I could know what issues my code has, and if some function already saves by themselves)
from session.
Related Issues (20)
- Session always response the last login session when enable rolling with iisnode proxy HOT 1
- When Run frontend and backend in diff domain it not working HOT 2
- Undefined session object with apollo v4 express and express-session HOT 1
- Regenerated session is re-saved even if not modified since save HOT 1
- Allow for sessions to be shared between subdomains. HOT 1
- Invalid argument type express-session "1.17.3" and redis "4.6.7", HOT 1
- Request session destroy does not always resolve before returning HOT 1
- [FEATURE REQUEST] Session Async Methods
- `SESSION.DESTROY()` DOES NOT DELETE SESSION. HOT 7
- A `destroy`ed session is still `touch`ed HOT 1
- cookie options won't get set HOT 13
- [Feature Request] Support of phasing out third-party cookies HOT 16
- req.sessionStore.all with typescript bug? HOT 7
- Don't `Set-Cookie` for static/public files? HOT 2
- Issue HOT 1
- Can't set partitioned cookie even though I updated all of the package HOT 6
- 'sha1' hash algorithm used at index.js is unsafe HOT 3
- Any good ways to refresh database data with a session? HOT 4
- Get session object from `req.session` outside of request context HOT 3
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 session.