0

This is my server code, please take a look at the comments in the code.

var app = express.createServer();
app.get('/', function(req, res){
    // create a session with the value of an email for example: [email protected]
});

// down here I want to check the session if the session exist
if( there is a session with value [email protected]){
    //do stuff  
}

1 Answer 1

2

The way sessions are implemented in Connect / Express doesn't allow for a custom session ID. This is partly because of security. So there's a bunch of things you can do.

  • Store everything in the session. Create an index somewhere (perhaps in a database) that maps email addresses to session IDs, so you can look up sessions by email.

  • Store only the email in the session. Keep the actual session data elsewhere (perhaps in a database), where you can fetch it by email address.

  • Create your own session middleware, perhaps based off Connect's code. The actual session code in Connect is a mere 300 lines. But be very careful to keep security features intact.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.