Skip to content

Instantly share code, notes, and snippets.

@zprima
Created January 27, 2019 11:29
Show Gist options
  • Save zprima/491a3706f9c33cd3b92ba1bb78919f00 to your computer and use it in GitHub Desktop.
Save zprima/491a3706f9c33cd3b92ba1bb78919f00 to your computer and use it in GitHub Desktop.
medium_p1_c4
// Routes
app.get("/api/login", (req, res) => {
// generate a constant token, no need to be fancy here
const token = jwt.sign({ "username": "Mike" }, jwtSecret, { expiresIn: 60 }) // 1 min token
// return it back
res.json({ "token": token })
});
app.get("/api/token/ping", (req, res) => {
// Middleware will already catch if token is invalid
// so if he can get this far, that means token is valid
res.json({ "msg": "all good mate" })
})
app.get("/api/ping", (req, res) => {
// random endpoint so that the client can call something
res.json({ "msg": "pong" })
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment