Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions final_project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,26 @@ app.use(express.json());

app.use("/customer",session({secret:"fingerprint_customer",resave: true, saveUninitialized: true}))

app.use("/customer/auth/*", function auth(req,res,next){
//Write the authenication mechanism here
app.use("/customer/auth/*", function auth(req, res, next) {
// 1. Check if session exists and has an access token
if (!req.session || !req.session.accessToken) {
return res.status(401).json({ message: "Unauthorized: No session token" });
}

const token = req.session.accessToken;

// 2. Verify JWT token
jwt.verify(token, "fingerprint_customer", (err, decoded) => {
if (err) {
return res.status(403).json({ message: "Forbidden: Invalid token" });
}

// 3. Save decoded info in req.user to use in downstream routes
req.user = decoded;
next(); // pass control to the next middleware or route handler
});
});


const PORT =5000;

Expand Down
Loading