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

lighty-auth

v1.1.0

Published

A lighweight OAuth 2.0 handler with Typescript

Readme

LightyAuth 🔐

LightyAuth is a simple, lightweight wrapper around Google OAuth 2.0 that makes it easy to authenticate users in your app.
It handles generating the authorization URL, exchanging authorization codes for access tokens, and fetching user profile data.


🚀 Features

  • Simple Google OAuth 2.0 integration
  • Get user profile data with minimal setup
  • TypeScript support
  • Promise-based API
  • Ideal for backend integrations and Express apps

📦 Installation

npm install lighty-auth

or

yarn add lighty-auth

🛠️ Usage

1. Initialize LightyAuth

import LightyAuth from "lighty-auth";

const auth = new LightyAuth({
  clientId: "YOUR_GOOGLE_CLIENT_ID",
  clientSecret: "YOUR_GOOGLE_CLIENT_SECRET",
  redirectUri: "http://localhost:3000/auth/callback",
});

2. Get Authorization URL

Redirect users to the authorization URL so they can grant access.

const url = auth.getAuthUrl();
console.log("Visit:", url);

When users log in and consent, Google redirects them to your redirectUri with a code parameter.


3. Exchange Code for Token

Use the code from the callback to obtain an access token.

const tokenData = await auth.getToken("AUTH_CODE_FROM_CALLBACK");
console.log(tokenData);

This returns an object similar to:

{
  "access_token": "ya29.a0AfH6SM...",
  "expires_in": 3599,
  "refresh_token": "1//0gdf2w...",
  "scope": "openid email profile",
  "token_type": "Bearer"
}

4. Fetch User Info

Once you have the access token, retrieve user information.

const user = await auth.fetchUser(tokenData.access_token);
console.log(user);

Example response:

{
  "sub": "1029384756",
  "name": "John Doe",
  "email": "[email protected]",
  "picture": "https://lh3.googleusercontent.com/a-/AOh14GgXx.jpg"
}

🧠 How It Works

  1. You create an OAuth Client in your Google Cloud Console.
  2. Initialize LightyAuth with your client credentials.
  3. Redirect users to the Google login page.
  4. Google redirects them back with an authorization code.
  5. Exchange that code for an access token.
  6. Use the access token to fetch user profile data.

🧩 Example Express Setup

import express from "express";
import LightyAuth from "lighty-auth";

const app = express();
const auth = new LightyAuth({
  clientId: process.env.GOOGLE_CLIENT_ID!,
  clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
  redirectUri: "http://localhost:3000/auth/callback",
});

app.get("/auth/google", (req, res) => {
  res.redirect(auth.getAuthUrl());
});

app.get("/auth/callback", async (req, res) => {
  const code = req.query.code as string;
  const token = await auth.getToken(code);
  const user = await auth.fetchUser(token.access_token);
  res.json(user);
});

app.listen(3000, () => console.log("Server running on http://localhost:3000"));

📄 License

MIT License © 2025 LightyAuth