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 🙏

© 2024 – Pkg Stats / Ryan Hefner

elf-authentication

v1.2.0

Published

Elf Authentication is a set of classes, methods and decorators to aid with authentication when using TypeORM and Express.

Downloads

2

Readme

Elf Authentication

Elf Authentication is a set of classes, methods and decorators to aid with authentication when using TypeORM and Express.

Classes


It exports a base ElfUser model class, which can be extended in the target project to include more properties related to the user, and a base ElfRole class, for adding user roles.

ElfUser


The ElfUserclass contains the following properties:

  • id
  • username
  • email
  • emailVerified
  • emailVerificationToken
  • passwordResetToken
  • passwordHash
  • isDisabled

ElfRole


The ElfRole class contains the following properties:

  • id
  • name
  • permissions

Decorators


Elf Authentication provides the following decorators for use in controllers.

@AuthorizeRoutes()


Decorate a controller class with this to apply authorization to all methods within that controller.

@Authorize()


Decorate a class method with this to apply authorization to just that method.

@AllowAnonymous()


Use this decorator to exempt a method from inherited authorization, such as one initiated with the AuthorizeRoutes decorator.

The AuthorizeRoutes and Authorize decorators accept options as an optional parameter. Set the checkPermissions flag to true to also authorize user permissions.

Methods


Elf Authentication makes available the following helper methods.

InitializeAuthentication


Use this to initialize authentication. Provide as first parameter, a reference to the TypeORM User Repository e.g. InitializeAuthentication(getRepository(User)). This is typically done before once a DB Connection has been made.

AuthenticateUser


Use this asynchronous method to authenticate a user. It's typically used at login, and accepts the express request and response objects. It returns a TokenResponse which contains token, expiresIn and tokenType e.g. const token = await AuthenticateUser(req, resp)

CreateUserSession


Use this asynchronous method to create a user session from a user. It's typically used after creating a user and accepts the request object and a user object. It also returns a TokenResponse. e.g. const token = await CreateUserSession(req, createdUser)

Customising


The following environment variables are available to use to customise the authorization process: | Tables | Are | | ------------- |-------------| | ELF_AUTH_CIPHER_KEY | Use this to define an encryption key for authorization. | | ELF_AUTH_EXPIRES_IN | Use this to customise how long the generated access token is valid for. The default value is 7 days. |