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
19 changes: 18 additions & 1 deletion final_project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,24 @@ 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
if (req.session.authorization) {
let token = req.session.authorization['accessToken']; // Access Token

// Verify JWT token for user authentication
jwt.verify(token, "access", (err, user) => {
if (!err) {
req.user = user; // Set authenticated user data on the request object
next(); // Proceed to the next middleware
} else {
return res.status(403).json({ message: "User not authenticated" }); // Return error if token verification fails
}
});

// Return error if no access token is found in the session
} else {
return res.status(403).json({ message: "User not logged in" });
}

});

const PORT =5000;
Expand Down
Loading