Reputation: 1
jwtmod not working to make user authenticate before consuming any API.
Here is my authenticated.js file:
import jwtmod from "jsonwebtoken";
export default async (req, res, next) => {const bearerHeader =
req.headers["authorization"];const token = bearerHeader &&
bearerHeader.split(" ")[1];if (token === null) return
res.sendStatus(401);console.log(token);
};
Here is the server.js file:
import dotenv from "dotenv";
import express from "express";
import test from "./test.js";
import authenticate from "./authenticate.js";
(async function () {dotenv.config();
const { PORT } = process.env;const app = express();const server =
app.listen(PORT, () =>console.log(Backend started on port ${PORT}));
app.use("/test",authenticate, test);})();
If i run the command "node server.js". i get "undefined" as response.
I need to have a bearer token after running the command "node server.js"
Upvotes: 0
Views: 17