Skip to content

Instantly share code, notes, and snippets.

@DomDumont
Created November 26, 2017 18:29
Show Gist options
  • Save DomDumont/83a19afe7b43c4a9398f771ebbf158ba to your computer and use it in GitHub Desktop.
Save DomDumont/83a19afe7b43c4a9398f771ebbf158ba to your computer and use it in GitHub Desktop.
export const authenticate = async ({ headers: { authorization } }, Users) => {
const token = authorization && HEADER_REGEX.exec(authorization)[1];
jwt.verify(token, process.env.JWT_SECRET, (err, decoded: any) => {
if (err) {
return undefined;
}
else {
return Users.findOne({ _id: new ObjectID(decoded._id) });
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment