Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not updating/Deleting for isAuth, isAdmin #131

Open
Anupyalsangikar opened this issue Nov 1, 2020 · 2 comments
Open

Not updating/Deleting for isAuth, isAdmin #131

Anupyalsangikar opened this issue Nov 1, 2020 · 2 comments

Comments

@Anupyalsangikar
Copy link

Hi sir,
I have added isAuth and isAdmin in the util.js and ProductRoute.js delete and put(..isAuth, isAdmin..) as parameter.
and also i have added

const isAuth = (req, res, next) => {
  const token = req.headers.authorization;

  if (token) {
    const onlyToken = token.slice(7, token.length);
    jwt.verify(onlyToken, config.JWT_SECRET, (err, decode) => {
      if (!err) {
        return res.status(401).send({ message: 'Invalid Token'});
      }
      req.user = decode;
      next();
      return;
    });
  } else {
    return res.status(401).send({ message: 'Token is not supplied.' });
  }
};

const isAdmin = (req, res, next) => {
    console.log('IS ADMIN ;;',req.user);

  if (req.user && req.user.isAdmin) {
    return next();
  }
  return res.status(401).send({ message: 'Admin Token is not valid.' });
};

here user is undefined
I am getting Admin token invalid

@Akshatjalan
Copy link

@basir sir same problem

@prishivgupta
Copy link

i am also having same problem does anyone have the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants