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

@pubinfo-pr/module-auth

v0.238.1

Published

Pubinfo 的认证模块,核心是“认证客户端 + 路由模块”两层能力:一层负责统一登录、回调认证、二维码渲染;一层负责把 `/auth/:type` 回调页和登录跳转逻辑挂到应用里。

Readme

@pubinfo/module-auth

Pubinfo 的认证模块,核心是“认证客户端 + 路由模块”两层能力:一层负责统一登录、回调认证、二维码渲染;一层负责把 /auth/:type 回调页和登录跳转逻辑挂到应用里。

它在做什么

  • 提供 createAuth(),统一封装第三方登录 Provider
  • 提供 createAuthModule(),把认证回调页和登录前跳转逻辑注册到 Pubinfo 应用
  • 内置多种 Provider:FourADingZJSsoCredentialsDefaultCredentials
  • 支持插件扩展,目前内置 twoFactor 双因子认证插件
  • 保留旧版 auth() 和一组兼容导出,但代码里已经标记为 deprecated

推荐接入方式

import { createAuth, createAuthModule } from '@pubinfo/module-auth';
import { FourA } from '@pubinfo/module-auth/providers';

const authClient = createAuth({
  baseURL: import.meta.env.VITE_APP_API_BASEURL,
  providers: [
    FourA({
      clientId: 'your-client-id',
      redirectUri: 'https://example.com/#/auth/4A',
    }),
  ],
});

export function setupAuth() {
  return createAuthModule(authClient, {
    pages: {
      signIn: '/login',
    },
    redirectTo: '/',
  });
}

工作方式

  • createAuth() 负责根据 provider 执行 signInauthenticaterenderQRCoderedirect
  • createAuthModule() 会注册 /auth/:type 页面
  • 当访问登录页路径时,如果存在 cas 类型 provider,会自动重定向到统一登录页
  • 当回调页认证成功时,会把 token 写入 userStore,然后跳转到 redirect 或默认目标页

内置 Provider

  • FourA: 4A 统一认证
  • DingZJ: 浙政钉扫码登录,支持 redirectembed
  • Sso: SSO 单点登录
  • Credentials: 自定义凭证登录 provider 外壳
  • DefaultCredentials: 对接底座默认用户名密码登录

插件扩展

createAuth() 支持 plugins。目前内置:

  • twoFactor: 扩展出 twoFactor.sendOtp()twoFactor.verifyOtp()
import { createAuth } from '@pubinfo/module-auth';
import { twoFactor } from '@pubinfo/module-auth/plugins';

导出

  • createAuthModule
  • createAuth
  • LoginWithFourA
  • auth
  • authenticate / redirect / renderQRCode / signIn

其中最后四个兼容旧用法,但应优先迁移到 authClient.xxx