SERVERSIDE
// Establishing Headers
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, authorization, Verification");
next();
});
app.use('/user', authMiddleware.authenticateToken, userRoutes);
CLIENTSIDE
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
I find it odd that this issue is occurring. When I exclude the authMiddleware, everything functions correctly.
SOLUTION: I believe the problem stems from using USE instead of specifying a specific route. Once I attach the middleware to a designated route, it operates smoothly. It seems that employing USE to apply middleware does not yield the desired results.