Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wouldn't use/fork Connect-Auth. This plugin of connect breaks the onion ring idea/architecture of connect and makes (IMHO) your code unreadable/brings unnecessary complexity.</p> <p>Authentification is too simple for a library. (If you a talking about a simple user login)</p> <p>I'm using a self written auth. You can find a simplified version below. It also depends on session-cookies but it can easily be replaced with persistant cookies.</p> <h2>A very simple authentication with connect</h2> <p>(It's complete. Just execute it for testing)</p> <pre><code>var connect = require('connect'); var urlpaser = require('url'); var authCheck = function (req, res, next) { url = req.urlp = urlpaser.parse(req.url, true); // #### // Logout if ( url.pathname == "/logout" ) { req.session.destroy(); } // #### // Is User already validated? if (req.session &amp;&amp; req.session.auth == true) { next(); // stop here and pass to the next onion ring of connect return; } // ######## // Auth - Replace this simple if with you Database or File or Whatever... // If Database, you need a Async callback... if ( url.pathname == "/login" &amp;&amp; url.query.name == "max" &amp;&amp; url.query.pwd == "herewego" ) { req.session.auth = true; next(); return; } // #### // User is not unauthorized. Stop talking to him. res.writeHead(403); res.end('Sorry you are unauthorized.\n\nFor a login use: /login?name=max&amp;pwd=herewego'); return; } var helloWorldContent = function (req, res, next) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('authorized. Walk around :) or use /logout to leave\n\nYou are currently at '+req.urlp.pathname); } var server = connect.createServer( connect.logger({ format: ':method :url' }), connect.cookieParser(), connect.session({ secret: 'foobar' }), connect.bodyParser(), authCheck, helloWorldContent ); server.listen(3000); </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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