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

@auth-guard/backend

v0.1.2

Published

Authentication backend library with OAuth, JWT, session management, and more

Readme

@auth-guard/backend

Authentication backend library for Auth Guard.

It provides:

  • Authentication functions: login, register, OAuth, verification, password reset
  • Session management: check auth, get sessions, token refresh
  • Profile and avatar management
  • JWT and cache configuration support

Installation

npm install @auth-guard/backend

Usage

Import the auth function and pass your models and configuration.

import type { IncomingMessage } from 'node:http'
import { auth } from "@auth-guard/backend";
import { User, Avatar, Profile, Session } from "your-service";
import { cache } from "your-cache-lib";
import { sendMail } from "your-mail-lib"; // or you can use @auth-guard/mail
import { log } from "your-log-lib";

const extractAccessToken = async (req: IncomingMessage) =>
    req.headers.authorization || (req.headers.token as string) || null;

const extractRefreshToken = async (req: IncomingMessage) => {
    const token: string | null = req.cookies?.["auth-refresh"];

    if (!token) {
        return null;
    }

    return `Bearer ${token}`;
};

const authGuard = auth({
	User,
	Avatar,
	Profile,
	Session,
	Cache: cache,
	Mail: {sendMail},
	extractToken: {
        access: extractAccessToken as () => Promise<string | null>,
        refresh: extractRefreshToken as () => Promise<string | null>,
    },,
	jwt: {
        expires: {
            access: 60 * 15,
            refresh: 60 * 60 * 24 * 7,
        },
        secret: <jwt-secret>
    },
	logger: log,
	// Optional:
	OAuth: {
        callbackUri: `<your-backend-url>/oauth/callback/`,
        providers: {
            [providers]: {
                clientId: <clinet-id>,
                clientSecret: <clinet-secret>,
            }
        },
    },
});

API

Authentication

login

const { login } = authGuard;

const result = await login({
	email: "[email protected]",
	password: "secure-password",
	deviceId,
    deviceName: ua.getOS().name || "Unknown",
    deviceType: ua.getBrowser().name || "Unknown",
});

register

const { register } = authGuard;

const result = await register({
	email: "[email protected]",
	password: "secure-password",
	name: "John Doe",
	deviceId,
    deviceName: ua.getOS().name || "Unknown",
    deviceType: ua.getBrowser().name || "Unknown",
});

oAuthStart

const { oAuthStart } = authGuard;

const { url, state } = oAuthStart("google");

loginWithProvider

const { loginWithProvider } = authGuard;

const result = await loginWithProvider({
	provider: 'google',
	code: <authorization-code>,
	state: <oauth-state>,
	deviceId,
    deviceName: ua.getOS().name || "Unknown",
    deviceType: ua.getBrowser().name || "Unknown",
});

startVerification

const { startVerification } = authGuard;

await startVerification({
	email: "[email protected]"
});

verifyAccount

const { verifyAccount } = authGuard;

await verifyAccount({
	email: "[email protected]",
	code: <verification-code>,
	deviceId,
    deviceName: ua.getOS().name || "Unknown",
    deviceType: ua.getBrowser().name || "Unknown",
});

Password

forgotPassword

const { forgotPassword } = authGuard;

const { id } = await forgotPassword({
	email: "[email protected]"
});

resetPassword

const { resetPassword } = authGuard;

await resetPassword({
	id: <user-id>,
	code: <reset-code>,
	password: "new-password",
	deviceId,
    deviceName: ua.getOS().name || "Unknown",
    deviceType: ua.getBrowser().name || "Unknown",
});

changePassword

const { changePassword } = authGuard;

await changePassword({
	password: "new-password",
	deviceId,
    deviceName: ua.getOS().name || "Unknown",
    deviceType: ua.getBrowser().name || "Unknown",
});

Auth State

checkAuth

const { checkAuth } = authGuard;

const result = await checkAuth(request);

loginRequired

const { loginRequired } = authGuard;

const result = await loginRequired(request);

Sessions

logout

const { logout } = authGuard;

await logout(request);

tokenRefresh

const { tokenRefresh } = authGuard;

const result = await tokenRefresh(request);

authStatus

const { authStatus } = authGuard;

const result = await authStatus(request);

getSessions

const { getSessions } = authGuard;

const sessions = await getSessions(request);

Profile

updateProfile

const { updateProfile } = authGuard;

const user = await updateProfile(request, {
	name: "Jane Doe",
});

Avatar

removeAvatar

[!WARNING] Not impl yet Suggested Api

const { removeAvatar } = authGuard;

await removeAvatar(request);

Types

Import types for TypeScript support:

import type {
	AuthType,
	AuthPropsType,
	AuthReturnType,
	TokenType,
	AvatarType,
	ProfileType,
	ProviderType,
	RoleType,
	SessionType,
	UserType,
} from "@auth-guard/backend";

Configuration

AuthPropsType

| Property | Type | Description | |----------|------|-------------| | User | UserModelType | User services to CRUD DB | | Avatar | AvatarModelType | Avatar services to CRUD DB | | Profile | ProfileModelType | Profile services to CRUD DB | | Session | SessionModelType | Session services to CRUD DB | | Cache | CacheConfigType | Cache to CRUD cache(get,set,remove) | | Mail | MailConfigType | Mail sender | | extractToken | TokenConfigType | Functions to extract Token | | jwt | JwtConfigType | JWT configuration | | logger | LoggerType | Logger instance |

License

MIT