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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@newput-newlink/authentication

v1.1.3

Published

The Authentication module is a secure and scalable solution for handling user authentication. It provides robust tools to manage user login, registration, and session handling, allowing developers to focus on building application features without reinvent

Readme

Newlink Authentication Module

The Authentication module is a secure and scalable solution for handling user authentication. It provides robust tools to manage user login, registration, and session handling, allowing developers to focus on building application features without reinventing the wheel.


Features

  1. JWT Authentication Secure token-based authentication for users.

  2. Password Encryption Automatically hash and store passwords securely.

  3. User Registration Easy-to-use methods for registering new users.

  4. Session Management Manage user sessions with built-in tools.

  5. Extensible Integrates seamlessly with other Newlink modules, such as Authorization and Notification.


Installation

Installation

Use the module via newlink-cli:

npx @newput-newlink/cli

Installation Process

During installation, the CLI will guide you through two key configuration steps:

-> Architecture Selection: Choose between Monolithic or Microservice architecture based on your project requirements. -> Authentication Setup: You'll be prompted to enable the authentication service. Enter 'Y' to include this feature in your installation.

The CLI tool handles all dependency installation and initial setup automatically, creating a production-ready service configured to your specifications. What Happens Next? After completing these steps, the NewLink CLI will:

Install all required dependencies Generate necessary configuration files Set up your chosen architecture Configure the authentication service (if selected) Initialize your project with the selected settings

Now your NewLink service is ready for development and deployment.



API Endpoints

  1. POST /authentication/login - Authenticate a user and generate a JWT token.
  2. POST /authentication/register - Register a new user.

npm install @newput-newlink/authentication

Environment Variables

The Authentication module requires several environment variables for proper configuration. Below is a table describing each variable, whether it is required, its purpose, and its default value:

| Environment Variable | Required | Description | Default | | --------------------- | -------- | ------------------------------------ | ----------- | | JWT_SECRET | Yes | Secret key used for signing JWTs | None | | JWT_EXPIRATION | No | JWT expiration time in seconds | 3600 | | OAUTH_CLIENT_ID | No | Client ID for OAuth integrations | None | | OAUTH_CLIENT_SECRET | No | Client Secret for OAuth integrations | None | | DB_TYPE | Yes | Database Type | postgres | | DB_HOST | Yes | Database host | localhost | | DB_PORT | No | Database port | 5432 | | DB_USERNAME | Yes | Database username | None | | DB_PASSWORD | Yes | Database password | None | | DB_NAME | Yes | Name of the authentication database | None |


Example .env File

Create a .env file in the root directory of your project and populate it with the necessary environment variables:

JWT_SECRET=your_jwt_secret
JWT_EXPIRATION=3600

OAUTH_CLIENT_ID=your_oauth_client_id
OAUTH_CLIENT_SECRET=your_oauth_client_secret

DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=auth_user
DB_PASSWORD=auth_password
DB_NAME=auth_db

Usage

Importing the Module

To use the Authentication module, import and configure it in your application:

import { AuthModule } from '@newput-newlink/authentication';

@Module({
	imports: [
		AuthModule.register({
			jwtSecret: process.env.JWT_SECRET,
			jwtExpiration: process.env.JWT_EXPIRATION || '3600',
			db: {
				host: process.env.DB_HOST,
				port: Number(process.env.DB_PORT),
				username: process.env.DB_USERNAME,
				password: process.env.DB_PASSWORD,
				name: process.env.DB_NAME,
			},
		}),
	],
})
export class AppModule {}

Example: User Registration

const user = await authService.register({
	username: 'john_doe',
	password: 'secure_password',
});
console.log('Registered user:', user);

Example: User Login

const token = await authService.login({
	username: 'john_doe',
	password: 'secure_password',
});
console.log('JWT Token:', token);

Testing

Run the tests to verify the module's functionality:

npm test

Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository.
  2. Create a feature branch.
  3. Commit your changes.
  4. Submit a pull request with a detailed description.

License

This module is licensed under the MIT License.