1.0.4 • Published 5 years ago

@3merge/express-auth-middleware v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Authentication middleware

Work in progress!

The user model

Discriminating the user model, the preferred approach, assigns a kind property to all documents. I recommend using the decorator functions in this module to get/set properties in the base as well.

Schema

PropertyTypeDescriptionDefault
activebooleanSystem-generated to keep track of "deleted" userstrue
email*stringSelf-explanatorynull
firstName*stringSelf-explanatorynull
frozenbooleanSomewhat of an alias for active, only setting it does not affect other propertiesfalse
langstringThe preferred locale (en-CA or fr-CA).en-CA
lastName*stringSelf-explanatorynull
loginAttemptsnumberUsed to block excessive login attempts (< 5)0
passwordpasswordUsed to authenticatenull
secret*stringUsed to read and write JWT tokens. Nullifying this would destroy all active sessionsnull
verifiedbooleanRepresents the validity of an email address. Login attempts are blocked without verificationfalse

Methods

NameDescriptionReturn
await Model.findByEmail(string)Lookup active users by email addressobject
await Model.findUnverifiedByEmail(string)Lookup unverified users by emailobject
await Model.findVerifiedByEmail(string)Lookup verified users by emailobject
await Model.findVerifiedById(string)Lookup verified users by idobject
await doc.setSecret()Generate secret tokenobject
await doc.verifyPassword(string, boolean)Compare string against stored password. Throws error if second parameter is trueboolean
await doc.deactivate()Deletes a user for most intents-and-purposesobject
doc.isBlockedIs the user allowed to login?boolean
doc.hasExpiredHas more than 24 hours elapsed since requesting verification?boolean
doc.isPermittedDoes the user have all the necessary properties to login?boolean