I am currently developing a web application using Express, Docker, and following a Three-layered architecture. In my app, I store user login information in a session and have blogposts as a key resource. To retrieve the blogpostId from the database in the Data access layer, I use the following query:
const db = require('./db')
exports.getBlogpostId = function(id ,callback){
const query = "SELECT * FROM blogposts WHERE blogId = ?"
const value = [id]
db.query(query, value, function(error, blogpost){
if(error){
callback("DatabaseError", null)
}else{
callback(null, blogpost)
}
})
}
Now in the Business logic layer, I need to verify whether the user is logged in before accessing blog postId data. Here's how I plan to handle it:
const blogRepo = require('../dal/blog-repository')
exports.getBlogpostId = function(id){
if(/*Check if the user is logged in*/){
return blogRepo.getBlogpostId(id)
}else{
throw "Unauthorized!"
}
}
I am looking for some guidance on how to implement the check for user login status in this section of the code. Specifically, how can I retrieve the stored session information from when the user initially logged in?
Thank you!