SyntaxError: отсутствует) после списка аргументов в Express. js с jsonwebtoken - PullRequest
1 голос
/ 05 мая 2020

я следую объяснению о JWT в expressjs, (я новичок ie в javascript), я следую всем инструкциям, но у меня есть ошибка при выполнении в узле:

jwt.verify(token, process.env.ACCESS_TOKEN as string , (err: any, user: any) => { 
SyntaxError: missing ) after argument list

Вот полный код:

const express = require ('express');
const jwt = require ('jsonwebtoken');
const env = require ('dotenv');

dotenv.config();

let port = 3400;
function authenticateToken(req, res, next) {
  // Gather the jwt access token from the request header
  const authHeader = req.headers['authorization']
  const token = authHeader && authHeader.split(' ')[1]
  if (token == null) return res.sendStatus(401) // if there isn't any token

  jwt.verify(token, process.env.ACCESS_TOKEN as string , (err: any, user: any) => {
    console.log(err)
    if (err) return res.sendStatus(403)
    req.user = user
    next() // pass the execution off to whatever request the client intended
  })
}
app.get('/api/userOrders', authenticateToken, (req, res) => {
    console.log(token);
})
app.listen(port, () => console.log(`Serve on http://localhost:${port}`))

Я не знаю, как справиться с этой ошибкой, мне нужен совет от людей. Заранее спасибо.

...