Skip to content

Instantly share code, notes, and snippets.

@alant
Created December 8, 2019 07:00
Show Gist options
  • Save alant/4d93af5de450acf6f36f511b5dea6d95 to your computer and use it in GitHub Desktop.
Save alant/4d93af5de450acf6f36f511b5dea6d95 to your computer and use it in GitHub Desktop.
const authCheck = (req, res, next) => {
let token = req.headers['x-access-token'] || req.headers['authorization']; // Express headers are auto converted to lowercase
if (token.startsWith('Bearer ')) {
// Remove Bearer from string
token = token.slice(7, token.length);
}
if (!token) return res.status(401).send({ auth: false, message: 'No token provided.' });
jwt.verify(token, process.env.JWT_SECRET, function(err, decoded) {
if (err) {
console.log("==> jwt error: ", err);
return res.status(500).send({ auth: false, message: 'Failed to authenticate token.' });
}
req.decoded = decoded;
next();
});
};
app.get("/profile", authCheck, async (req, res) => {
// console.log("==> /profile req.decoded: ", req.decoded);
const profile = await User.findUser(req.decoded.email);
res.json({
user: profile
});
});
@fabianm777
Copy link

Keybase proof

I hereby claim:

  • I am fabianm777 on github.
  • I am fabianmonrroy (https://keybase.io/fabianmonrroy) on keybase.
  • I have a public key ASDpjOKnGfM9mPS1VpH6KnN21g83Fk_AWU-uxxu0oPrW_go

To claim this, I am signing this object:

{
  "body": {
    "key": {
      "eldest_kid": "0120e98ce2a719f33d98f4b55691fa2a7376d60f37164fc0594faec71bb4a0fad6fe0a",
      "host": "keybase.io",
      "kid": "0120e98ce2a719f33d98f4b55691fa2a7376d60f37164fc0594faec71bb4a0fad6fe0a",
      "uid": "a801ae9d36b45b86e6d1646679655c19",
      "username": "fabianmonrroy"
    },
    "merkle_root": {
      "ctime": 1575788382,
      "hash": "ce8d6e70acc8777767495299aa28288646c5cc71be2ce78c24577055fecd51a76e07065c7fefaf196c3d3e50010269181a38858df83f95f7068117a788507159",
      "hash_meta": "86ad703ca6de6a42297bc07c3df0a91357eaeca341a7a2285b71e285986eb99b",
      "seqno": 12783790
    },
    "service": {
      "entropy": "4VVhQ0UjjWJ4/jUhtOu8yu5o",
      "name": "github",
      "username": "fabianm777"
    },
    "type": "web_service_binding",
    "version": 2
  },
  "client": {
    "name": "keybase.io go client",
    "version": "5.0.0"
  },
  "ctime": 1575788255,
  "expire_in": 504576000,
  "prev": "a5191bbddcd6ab2d6e5247e22f85d61278dcff26669e4176fc30d3143c3fe948",
  "seqno": 12,
  "tag": "signature"
}

with the key ASDpjOKnGfM9mPS1VpH6KnN21g83Fk_AWU-uxxu0oPrW_go, yielding the signature:

hKRib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEg6YzipxnzPZj0tVaR+ipzdtYPNxZPwFlPrscbtKD61v4Kp3BheWxvYWTESpcCDMQgpRkbvdzWqy1uUkfiL4XWEnjc/yZmnkF2/DDTFDw/6UjEIEbsH5FwtzD9Uk66fw9gO7f/FGlMrxqyRujdmLiP8GCJAgHCo3NpZ8RA5TlUltheV2xJ1iPm72uPuNWHJe72rS7zk20cclbLLPjBNncTGUaRGvBqOitMw2OMEJcddm1NEI9a6uyrPFs+C6hzaWdfdHlwZSCkaGFzaIKkdHlwZQildmFsdWXEIG5vY2sWXJivtwxRoOBp60YvPxSXUSheiW1IQkOLDdDUo3RhZ80CAqd2ZXJzaW9uAQ==

And finally, I am proving ownership of the github account by posting this as a gist.

My publicly-auditable identity:

https://keybase.io/fabianmonrroy

From the command line:

Consider the keybase command line program.

# look me up
keybase id fabianmonrroy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment