npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@codestra/authentication-manager

v1.2.6

Published

Full authentication helper functions

Readme

@codestra/authentication-manager

authentication-manager is a package that provides helper functions for user management.

Installation

Use npm for installation:

npm install @codestra/authentication-manager

Or use yarn for installation:

yarn add @codestra/authentication-manager

Usage

You need to have a running mongoose connection.

Example

The following is a full example of all the functions and how you can use them.

// The model needs to at least have these fields
const UserSchema = new mongoose.Schema({
  email: { type: String, required: true, unique: true },
  password: { type: String, required: true },
  salt: { type: String },
  passwordResetToken: { type: String },
  passwordResetExpires: { type: Number },
  activated: { type: Boolean },
  activationToken: { type: String },
});
const User = mongoose.model('User', UserSchema);

// creates a new user and returns the modelSignUpData._id and modelSignUpData.activationToken
const modelSignUpData = await modelSignUp({
  Model: User,
  variables: { email: '[email protected]', password: 'verymuchsecure' },
});

// activates the user with the activation token and returns a authentication token
const authenticationTokenActivate = await modelActivate({
  Model: User,
  variables: { activationToken: modelSignUpData.activationToken },
});

// returns the authentication modelSignInData.token and modelSignInData._id if the password was right
const modelSignInData = await modelSignIn({
  Model: User,
  variables: { email: '[email protected]', password: 'verymuchsecure' },
});

// verifies the authentication token
const authentication1 = modelVerify({ token: authenticationTokenActivate });
// or
const authentication2 = modelVerify({ token: modelSignInData.token });

// returns a password reset token that we need to give the user to reset
const passwordResetToken = await modelRequestResetPassword({
  Model: User,
  variables: { email: '[email protected]' },
});

// verifies that the password reset token was right and sets the new password
const email = await modelRequestUpdatePassword({
  Model: Vendor,
  variables: { passwordResetToken, email: '[email protected]', password: 'newverysecure' },
});

Functions

genRandomString(length)

| Param | Type | Description | | ------ | ------------------- | ----------------------------------- | | length | number | Length of the random string. |

createHash(password, salt)

| Param | Type | Description | | -------- | ------------------- | ------------------------------- | | password | string | List of required fields. | | salt | string | Data to be validated. |

createHash~hash

modelActivate(parameters) ⇒ Promise.<string>

Returns: Promise.<string> - the jwt for the authentication

| Param | Type | Description | | ------------------------------------ | --------------------------- | --------------------------------------------------------------------------- | | parameters | Object | function parameters | | parameters.Model | mongoose.Model | mongodb model | | parameters.variables.activationToken | string | the activation token for which model we want to activate the account | | parameters.onCompleted | function | callback on completed. Returns the token. |

modelRequestResetPassword(parameters) ⇒ Promise.<string>

Returns: Promise.<string> - returns the reset token

| Param | Type | Description | | -------------------------- | --------------------------- | ------------------------------------------------------------ | | parameters | Object | function parameters | | parameters.Model | mongoose.Model | mongodb model | | parameters.variables.email | string | the email for which we want to reset the password | | parameters.onCompleted | function | callback on completed. Returns the passwordResetToken |

modelRequestUpdatePassword(parameters) ⇒ Promise.<string>

Returns: Promise.<string> - the found email for which we want to resend the activation

| Param | Type | Description | | --------------------------------------- | --------------------------- | ----------------------------------------------------------- | | parameters | Object | function parameters | | parameters.Model | mongoose.Model | mongodb model | | parameters.variables.email | string | the email for which we want to resend the activation | | parameters.variables.password | string | the new password | | parameters.variables.passwordResetToken | string | the passwordResetToken | | parameters.onCompleted | function | callback on completed. Returns the e-mail. |

modelResendActivation(parameters) ⇒ Promise.<string>

Returns: Promise.<string> - the found email for which we want to resend the activation

| Param | Type | Description | | -------------------------- | --------------------------- | ----------------------------------------------------------- | | parameters | Object | function parameters | | parameters.Model | mongoose.Model | mongodb model | | parameters.variables.email | string | the email for which we want to resend the activation | | parameters.onCompleted | function | callback on completed. Returns the activationToken. |

modelSignIn(parameters) ⇒ Promise.<string>

Returns: Promise.<string> - the jwt for the authentication

| Param | Type | Description | | ----------------------------- | --------------------------- | --------------------------------------------- | | parameters | Object | function parameters | | parameters.Model | mongoose.Model | mongodb model | | parameters.variables.email | string | the email | | parameters.variables.password | string | the password | | parameters.onCompleted | function | callback on completed. Returns the jwt |

modelSignUp(parameters) ⇒ Promise.<{activationToken: string, _id: string}>

Returns: Promise.<{activationToken: string, _id: string}> - the activationtoken and _id as a string

| Param | Type | Description | | ----------------------------- | --------------------------- | ------------------------------------------------------------------- | | parameters | Object | function parameters | | parameters.Model | mongoose.Model | mongodb model | | parameters.variables.email | string | the email which will be used for registration made lowercase | | parameters.variables.password | string | the password | | parameters.onCompleted | function | callback on completed. Returns the _id |

modelVerify(parameters) ⇒ JwtPayload | null

Returns: JwtPayload | null - the jwt for the authentication. If verified correctly, returns {id} so for mongoose, you need to make it _id

| Param | Type | Description | | ---------------- | ------------------- | -------------------------- | | parameters | Object | function parameters | | parameters.token | string | mongodb model |

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT