I'm trying to use a middleware in Express but I can't get it to work I get infinite loading time when I make a request. I searched on stackoverflow but I couldn't find any examples that used an async await middleware stored in a separate file. Can someone point me in the right direction?
isAuthenticated.js
const Auth = require('../auth/auth')
const isAuthenticated = async () => {
return async (request, response, next) => {
const token = request.cookies.token;
try {
const JWTVerify = await Auth.verifyJWTToken(token);
next()
} catch (error) {
response.json({ status: "failed", message: "Authentication failed invalid token" });
response.end();
}
}
}
module.exports = isAuthenticated
Server.js
const isAuthenticated = require('./middleware/isAuthenticated')
app.post('/some-route', isAuthenticated, async (request, response) => {
});