Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With the use of ExpressJS sessions, you may hold session cookies. You need cookieParser and a session store. But if you don't want to extend this ExpressJS functionality (this is what i understand from your message), you should manage your own sessions with a token or a secret temporary string.</p> <p>Although I strongly advise you to use ExpressJS sessions, this is how you should do it without ExpressJS cookies.</p> <ul> <li>On each login, create a unique token and store it for future lookup.</li> <li>On each request, send that token from the client and check it on the server. Redirect to the login if the token is invalid</li> </ul> <p>Here is the login code example:</p> <pre><code>app.post("/login", function(req, res) { if(req.body.username &amp;&amp; req.body.password) { // check username and password if(authenticated) { // create a token and store it with the current date (if you want it to expire) var token = generateAndStoreRandomString(req.body.username); res.redirect("http://your.domain/path?token=" + token); return; } // Do something if username or password wrong } // Do something if no username or password }); </code></pre> <p>Now, on every request:</p> <pre><code>app.get("somePath", function(req, res) { if(!req.query.token) { res.redirect("http://your.domain/login"); return; } // Check token in database, if it exists and it hasn't expired if(!authenticated) { res.redirect("http://your.domain/login"); return; } // The user is authenticated. Do the actions required by "somePath" }); </code></pre> <p>Try to have a process clean up the expired tokens every once in a while, since they will add up eventually. If you want to use ExpressJS cookieParser and session store, there are a lot of articles and examples. Post another question if you are having troubles with those.</p> <p>I shall repeat myself, try using ExpressJS sessions. This method can be easily hijacked if you use http instead of https.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload