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

@leancodepl/login-manager

v9.7.0

Published

OAuth2 and token-based authentication management utilities

Readme

@leancodepl/login-manager

OAuth2 authentication management with token storage and refresh capabilities.

Features

  • OAuth2 authentication - Standard-compliant implementation
  • Multiple storage options - Local, session, or memory storage
  • Token refresh - Automatic refresh handling
  • Social login - Facebook, Google and LinkedIn integrations

Installation

npm install @leancodepl/login-manager
# or
yarn add @leancodepl/login-manager

API

AsyncLoginManager

Manages OAuth2 authentication with asynchronous token storage.

Parameters:

  • storage: AsyncTokenStorage - Token storage implementation
  • endpoint: string - OAuth2 server endpoint
  • clientSecret: string | undefined - Client secret for authentication
  • clientId: string - OAuth2 client identifier
  • scopes: string - Space-separated OAuth2 scopes
  • additionalParams?: Record<string, string> - Additional OAuth2 parameters

SyncLoginManager

Manages OAuth2 authentication with synchronous token storage.

Parameters:

  • storage: SyncTokenStorage - Token storage implementation
  • endpoint: string - OAuth2 server endpoint
  • clientSecret: string | undefined - Client secret for authentication
  • clientId: string - OAuth2 client identifier
  • scopes: string - Space-separated OAuth2 scopes
  • additionalParams?: Record<string, string> - Additional OAuth2 parameters

LocalTokenStorage

Stores OAuth2 tokens in browser localStorage.

Parameters:

  • tokenKey?: string - localStorage key for access token (default: "token")
  • refreshKey?: string - localStorage key for refresh token (default: "refresh_token")
  • expiryKey?: string - localStorage key for expiry date (default: "expiration_date")

SessionTokenStorage

Stores OAuth2 tokens in browser sessionStorage.

Parameters:

  • tokenKey?: string - sessionStorage key for access token (default: "token")
  • refreshKey?: string - sessionStorage key for refresh token (default: "refresh_token")
  • expiryKey?: string - sessionStorage key for expiry date (default: "expiration_date")

MemoryTokenStorage

Stores OAuth2 tokens in memory.

FacebookClient

Integrates Facebook Login SDK for web applications.

Parameters:

  • facebookAppId: string - Facebook App ID
  • facebookPermissions: string - Comma-separated Facebook permissions

CannotRefreshToken

Error thrown when token refresh fails.

Usage Examples

Basic Authentication

import { SyncLoginManager, LocalTokenStorage } from "@leancodepl/login-manager"

const tokenStorage = new LocalTokenStorage()
const loginManager = new SyncLoginManager(
  tokenStorage,
  "https://api.example.com",
  "client_secret",
  "client_id",
  "openid profile email",
)

const result = await loginManager.trySignIn("[email protected]", "password")
if (result.type === "success") {
  console.log("Signed in successfully")
}

Session-based Authentication

import { AsyncLoginManager, SessionTokenStorage } from "@leancodepl/login-manager"

const tokenStorage = new SessionTokenStorage()
const loginManager = new AsyncLoginManager(
  tokenStorage,
  "https://api.example.com",
  undefined, // No client secret for public clients
  "public_client_id",
  "openid profile",
)

await loginManager.load()
const isSignedIn = await loginManager.isSigned()
console.log("User signed in:", isSignedIn)

Facebook Login Integration

import { FacebookClient, SyncLoginManager, LocalTokenStorage } from "@leancodepl/login-manager"

const facebookClient = new FacebookClient("your-facebook-app-id", "email,public_profile")
const loginManager = new SyncLoginManager(
  new LocalTokenStorage(),
  "https://api.example.com",
  "client_secret",
  "client_id",
  "openid profile",
)

facebookClient.setup()
facebookClient.login(async accessToken => {
  const result = await loginManager.trySignInWithFacebook(accessToken)
  if (result.type === "success") {
    console.log("Facebook login successful")
  }
})

Token Management

import { CannotRefreshToken, SyncLoginManager, LocalTokenStorage } from "@leancodepl/login-manager"

const tokenStorage = new LocalTokenStorage()
const loginManager = new SyncLoginManager(
  tokenStorage,
  "https://api.example.com",
  "client_secret",
  "client_id",
  "openid profile",
)

try {
  const token = await loginManager.getToken()
  console.log("Access token:", token)
} catch (error) {
  if (error instanceof CannotRefreshToken) {
    console.log("Token expired, user needs to sign in again")
    await loginManager.signOut()
  }
}

Authentication State Monitoring

import { SyncLoginManager, LocalTokenStorage } from "@leancodepl/login-manager"

const tokenStorage = new LocalTokenStorage()
const loginManager = new SyncLoginManager(
  tokenStorage,
  "https://api.example.com",
  "client_secret",
  "client_id",
  "openid profile",
)

loginManager.onChange(isSignedIn => {
  if (isSignedIn) {
    console.log("User is now signed in")
  } else {
    console.log("User signed out")
  }
})

Multiple Authentication Providers

import { SyncLoginManager, LocalTokenStorage } from "@leancodepl/login-manager"

const tokenStorage = new LocalTokenStorage()
const loginManager = new SyncLoginManager(
  tokenStorage,
  "https://api.example.com",
  "client_secret",
  "client_id",
  "openid profile",
)

const googleResult = await loginManager.trySignInWithGoogle("google_access_token")
const linkedinResult = await loginManager.trySignInWithLinkedIn("linkedin_access_token")
const otpResult = await loginManager.trySignInWithOneTimeToken("one_time_token")