Skip to content

Instantly share code, notes, and snippets.

@DomDumont
Created November 26, 2017 18:22
Show Gist options
  • Save DomDumont/3dce2829e9789ac5578503244a863768 to your computer and use it in GitHub Desktop.
Save DomDumont/3dce2829e9789ac5578503244a863768 to your computer and use it in GitHub Desktop.
const HEADER_REGEX = /bearer token-(.*)$/;
/**
* This is an extremely simple token. In real applications make
* sure to use a better one, such as JWT (https://jwt.io/).
*/
module.exports.authenticate = async ({headers: {authorization}}, Users) => {
const email = authorization && HEADER_REGEX.exec(authorization)[1];
return email && await Users.findOne({email});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment