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

@open_auth/auth

v0.1.7

Published

A simple and lightweight authentication library for web apps using **One-Time Passwords (OTP)** and **Password-based login**. πŸ”’ Built in **TypeScript**, compiled for both **CommonJS** and **ESModules**.

Downloads

46

Readme

@open_auth/auth πŸš€

A simple and lightweight authentication library for web apps using One-Time Passwords (OTP) and Password-based login. πŸ”’
Built in TypeScript, compiled for both CommonJS and ESModules.

βœ… Supports:

  • βœ‰οΈ Sign Up (OTP and Password based)
  • βœ… Sign In (OTP and Password based)
  • πŸ” Resend OTP
  • πŸšͺ Sign Out

πŸ” How It Works

  • This auth system uses JWT (JSON Web Tokens) for user sessions.
  • JWTs are stored securely in HTTP-only cookies.
  • The backend generates tokens after sign-in, and the client stores them in the browser using cookies.
  • This setup is secure and works well across multiple platforms.

πŸ“¦ Installation

# npm
npm install @open_auth/auth
# yarn
yarn add @open_auth/auth

🧩 Setup

🌍 Environment Variables

Backend App

These variables are required in your backend server (.env file):

| Variable | Description | |------------------|-------------------------------------------| | DATABASE_URL | PostgreSQL connection string | | FROM_EMAIL | Your email for sending OTPs | | APP_PASSWORD | Google app password for email | | AUTH_SECRET | Secret used to sign JWT tokens |

DATABASE_URL=postgresql://user:pass@localhost:5432/dbname
[email protected]
APP_PASSWORD=your-google-app-password
AUTH_SECRET=your-secure-auth-secret

🐘 Note: PostgreSQL is required as the backend database.


πŸ“ Usage Note

Each auth function is meant to be used on its specific page:

| Route Path | Function to Call | |------------------|--------------------------| | /signUp | signUp() | | /signUpPassword | signUpPassword() | | /signIn | signIn() | | /signInPassword | signInPassword() |

❗️ Calling these functions outside their intended pages may cause issues.


πŸ“¦ Initialize Client

You must create an instance of the client using the backend URL:

import { CreateOpenAuthClient } from "@open_auth/auth/client";

const openAuth = new CreateOpenAuthClient({
  backendUrl: "http://localhost:3000" // or process.env.NEXT_PUBLIC_BACKEND_URL
});

export default openAuth;

You can place this in lib/open_auth.ts and import it throughout your app.
Alternatively, use directly where needed.


πŸ”§ Project Configuration

Make sure your project includes this in tsconfig.json or jsconfig.json:

{
  "compilerOptions": {
    "module": "esnext",
    "moduleResolution": "bundler"
  }
}

πŸ§ͺ Usage

Import from your openAuth instance:

import openAuth from "@/lib/open_auth";

await openAuth.signUp({ username: "user", email: "[email protected]" });

Each function returns { err: string } or a success response.


🧬 Examples

🟣 signUp

React

await openAuth.signUp({ username: "user", email: "[email protected]" });

Vanilla JS (CommonJS)

const { CreateOpenAuthClient } = require("@open_auth/auth/client");
const openAuth = new CreateOpenAuthClient({ backendUrl: "http://localhost:3000" });

openAuth.signUp({ username: "user", email: "[email protected]" });

🟣 signUpPassword

await openAuth.signUpPassword({ password: 123456 });
const { CreateOpenAuthClient } = require("@open_auth/auth/client");
const openAuth = new CreateOpenAuthClient({ backendUrl: "http://localhost:3000" });

openAuth.signUpPassword({ password: 123456 });

🟒 signIn

await openAuth.signIn({ email: "[email protected]" });
const { CreateOpenAuthClient } = require("@open_auth/auth/client");
const openAuth = new CreateOpenAuthClient({ backendUrl: "http://localhost:3000" });

openAuth.signIn({ email: "[email protected]" });

🟒 signInPassword

await openAuth.signInPassword({ password: 123456 });
const { CreateOpenAuthClient } = require("@open_auth/auth/client");
const openAuth = new CreateOpenAuthClient({ backendUrl: "http://localhost:3000" });

openAuth.signInPassword({ password: 123456 });

πŸ” resendPass

await openAuth.resendPass();
const { CreateOpenAuthClient } = require("@open_auth/auth/client");
const openAuth = new CreateOpenAuthClient({ backendUrl: "http://localhost:3000" });

openAuth.resendPass();

πŸšͺ signOut

openAuth.signOut();
const { CreateOpenAuthClient } = require("@open_auth/auth/client");
const openAuth = new CreateOpenAuthClient({ backendUrl: "http://localhost:3000" });

openAuth.signOut();

πŸ› οΈ Backend Server Setup

🧩 Express.js Example

const express = require("express");
const cors = require("cors");
import { OpenAuthBackend } from '@open_auth/auth'
require("dotenv").config();

const app = express();
app.use(cors());
app.use(express.json());

const port = process.env.PORT || 3000;

const open_auth_backend = new OpenAuthBackend();
app.post("/api/auth/open_auth", (req, res) => {
  open_auth_backend.Main(req.headers.from, req.body).then(data => {
    res.json(data);
  });
});

app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});

πŸ”΅ Next.js Example (app/api route)

import { NextRequest, NextResponse } from 'next/server'
import { OpenAuthBackend } from '@open_auth/auth'

export async function POST(req) { // req: NextRequest for route.ts
    const data = await req.json()
    const from = req.headers.get('from')
    const open_auth_backend = new OpenAuthBackend();
    const res = await open_auth_backend.Main(from , data)
    return NextResponse.json(res)
}

πŸ“š API Reference

| Function | Params | Returns | |-------------------|-----------------------------------|----------------------------------------| | signUp | { username, email } | Promise<{ err: any } | undefined> | | signUpPassword | { password } | Promise<{ err: any } | undefined> | | signIn | { email } | Promise<{ err: any } | undefined> | | signInPassword | { password } | Promise<{ err: any } | undefined> | | resendPass | none | Promise<{ err: any } or { message }> | | signOut | none | { message: string } |


πŸ“„ License

MIT