This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jwt = require('jsonwebtoken') | |
const verifyToken = (req, res, next) => { | |
const token = req.headers['x-access-token'] || req.headers['authorization'] | |
if(token){ | |
jwt.verify(token, "chor", (err, decoded) => { | |
if(err){ | |
res.status(403).json({ err }) | |
} | |
if(decoded){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const router = require("express").Router() | |
const auth = require("../middleware/auth") | |
router.get("/", (req, res) => { | |
res.status("200").json({"message": "Hello, Welcome"}) | |
}) | |
router.post("/login", auth.signToken) | |
router.get("/data", auth.verifyToken, (req, res) => { | |
res.status("200").json({email: req.decoded}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const cors = require('cors') | |
const bodyParser = require('body-parser'); | |
const app = express() | |
app.use(cors()) | |
app.use(express.json()) | |
app.use(bodyParser.json()) | |
app.use(function (req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*") // update to match the domain you will make the request from |