Add - cookieHandler.js
Pre-release
Pre-release
photovoyagehelp
released this
21 Mar 21:49
·
113 commits
to main
since this release
Setting up the Express application:
const express = require('express');
const { configureCookieParser, setLoggedInUserCookie } = require('./cookieHandler'); // Assuming the module is in the cookieHandler.js file
const app = express();
// Configure the cookie-parser middleware
configureCookieParser(app);
// Route to set the authenticated user cookie
app.get('/login', (req, res) => {
// Simulating a successful login
const username = 'exampleUser';
const expires = new Date(Date.now() + 3600000); // Cookie expires in 1 hour (3600000 ms)
setLoggedInUserCookie(res, username, expires);
res.send('Authenticated user cookie set successfully.');
});
app.listen(3000, () => {
console.log('Server listening on port 3000...');
});
Example request to set the authenticated user cookie:
- Suppose you access http://localhost:3000/login in your browser.
- This route will simulate a successful login and set a cookie in your browser named 'loggedInUser' with the value 'exampleUser'.
This is a basic example, and you'll need to adjust it according to your application's needs and structure. Additionally, you'll need to have Express and the cookie-parser module installed and configured in your project for this to work correctly.