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

authentix

v1.1.2

Published

**Authentix** is an authentication package that simplifies user authentication by providing easy-to-use functions for user signup, login, token generation, middleware, and Google OAuth authentication.

Downloads

5

Readme

Authentix

Authentix is an authentication package that simplifies user authentication by providing easy-to-use functions for user signup, login, token generation, middleware, and Google OAuth authentication.

Features

  • Easy configuration of user database
  • Support for username/password or email/password authentication
  • Google OAuth authentication
  • Token-based authentication with access and refresh tokens
  • Middleware for token verification
  • Simple API for user authentication

Installation

npm install authentix

user-model.js

import { configureDB } from 'authentix';

const userSchema = new Schema({
  email: { type: String, required: false},
  username: { type: String, required: false},
  password: { type: String, required: false },
});

const User = mongoose.model('User', userSchema);

//Configure Your Database, username and password is the mongodb field key
configureDB(User, {primaryField: 'username', passwordField: 'password', google: 'email'})

routes.js

import { setConfig, emailSignup, googleLogin, login, loginRequired, logout, signup, verifyOtp } from 'authentix';

const config_data = {
  JWT_SECRET_KEY:  'your-secret-key-goes-here',
  GOOGLE_CLIENT_ID: 'your-google-client-id-goes-here'
}

setConfig(config_data) // the provided secret keys would be used for further processes

// ===========> Login routes <===============
app.post('/auth/google', googleLogin); //
app.post('/credential-login', login);
app.post('/credential-signup', signup);
app.post('/email-login', emailSignup);
app.post('/verify-otp', verifyOtp);
app.post('/email-signup', signup);
app.get('/logout', logout);

Authentix

Authentix is an authentication package that simplifies user authentication by providing easy-to-use functions for user signup, login, token generation, middleware, and Google OAuth authentication.

Features

=> Easy configuration of user database => Support for username/password or email/password authentication => Google OAuth authentication => Token-based authentication with access and refresh tokens => Middleware for token verification => Simple API for user authentication

Installation

npm install authentix

Configuration

To get started, you need to configure your user database and set up the authentication fields.

User Model Configuration

First, define your user schema and configure the database with authentix.

// user-model.js
import mongoose from 'mongoose';
import { configureDB } from 'authentix';

const userSchema = new mongoose.Schema({
  email: { type: String, required: false },
  username: { type: String, required: false },
  password: { type: String, required: false },
});

const User = mongoose.model('User', userSchema);

// Configure your database, primary field, and password field
configureDB(User, {
  primaryField: 'username', // or 'email'
  passwordField: 'password',
  google: 'email' // field used for Google OAuth
});

Setting Up Routes

Set up your authentication routes using authentix functions.

// routes.js
import express from 'express';
import { setConfig, emailSignup, googleLogin, login, loginRequired, logout, signup, verifyOtp } from 'authentix';

const app = express();

const config_data = {
  JWT_SECRET_KEY: 'your-secret-key-goes-here',
  GOOGLE_CLIENT_ID: 'your-google-client-id-goes-here'
};

// Set the configuration for authentix
setConfig(config_data);

// Define your authentication routes
app.post('/auth/google', googleLogin);          // Google OAuth login
app.post('/credential-login', login);           // Credential login
app.post('/credential-signup', signup);         // Credential signup
app.post('/email-login', emailSignup);          // Email login
app.post('/verify-otp', verifyOtp);             // Verify OTP
app.post('/email-signup', signup);              // Email signup
app.get('/logout', logout);                     // Logout

// Example of a protected route
app.get('/protected', loginRequired, (req, res) => {
  res.send('This is a protected route');
});

// Start the server
app.listen(3000, () => {
  console.log('Server running on http://localhost:3000');
});

Rules

=> Make sure to use the loginRequired middleware from authentix, as we have stored the access and refresh tokens in the cookies with httpOnly:true, so that those cookies cant be accessible from frontend (To make it secure from XSS attacks).