Skip to content

Instantly share code, notes, and snippets.

@timwis
Created September 8, 2016 11:10
Show Gist options
  • Save timwis/e575a86d6631c1081e68cf43154ef98f to your computer and use it in GitHub Desktop.
Save timwis/e575a86d6631c1081e68cf43154ef98f to your computer and use it in GitHub Desktop.
couchdb view
/* global emit */
const TOKEN_LIFESPAN = 30 // seconds
module.exports = {
_id: '_design/users',
views: {
byEmail: {
map: function (doc) {
emit(doc.metadata.email)
}
},
byResetToken: {
map: function (doc) {
if (doc.metadata.resetToken &&
((Date.now() - doc.metadata.resetToken.created) / 1000) <= TOKEN_LIFESPAN) {
emit(doc.metadata.resetToken.token)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment