DEV Community

akgn1991
akgn1991

Posted on

Auth using jsonwebtoken(why user is equal to req.user)

here is the code for auth using jsonwebtoken which i got from youtube tutorial why req.user =user

import jwt from "jsonwebtoken";
const auth = (req, res, next) => {
  try {
    const token = req.header("Authorization");
    if (!token) return res.status(400).json({ msg: "Invalid Authentication" });
    jwt.verify(token, process.env.SECRET_JWT, (err, user) => {
      if

Discussion (1)

Collapse
hilleer profile image
Daniel Hillmann

Hi :-) I have added an answer to your question. Let me know if anything is still unclear then I can update accordingly.