File size: 571 Bytes
d145b59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const crypto = require("crypto");

function generateToken() {
  return crypto.randomBytes(35).toString("hex");
}

module.exports = async function(req, res) {
  const ip = req._ip;
  const token = generateToken()

  global.tokenVd = global.tokenVd.filter(entry => entry.ip !== ip);
  global.tokenVd.push({
    ip,
    token
  });
  res.setHeader("X-Auth-Token", token);
  res.status(200).json({
    status: "success",
    message: "Your Ip device Has been stored",
    timestamp: Date.now(),
    device: {
      ip,
      "User-Agent": req.get("user-agent"),
    },
  })
}