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

@shixm/universal-auth

v1.0.0

Published

A universal authentication plugin supporting phone verification, password login, third-party login, and more

Downloads

3

Readme

Universal Authentication Plugin

一个功能完整的通用认证插件,支持多种登录方式和安全特性。

特性

  • 多种登录方式
    • 手机号验证码登录
    • 账号密码登录
    • 邮箱登录
    • 第三方登录(微信、支付宝)
  • 安全特性
    • 图形验证码
    • 7天内自动登录
    • 记住密码
    • 忘记密码功能
  • 用户管理
    • 个人信息管理
    • 退出登录

安装

npm install universal-auth

使用方法

1. 配置认证服务

import { AuthService } from 'universal-auth';

const authService = new AuthService({
  apiBaseUrl: 'https://your-api-url.com',
  tokenKey: 'auth_token',
  autoLoginKey: 'auto_login',
  rememberMeKey: 'remember_me',
  captchaEnabled: true,
  thirdPartyEnabled: true,
  tokenExpiration: 7 * 24 * 60 * 60 * 1000, // 7 days
});

2. 使用登录组件

import { LoginForm } from 'universal-auth';

function App() {
  const handleLoginSuccess = (user) => {
    console.log('Login successful:', user);
  };

  const handleLoginError = (error) => {
    console.error('Login failed:', error);
  };

  return (
    <LoginForm
      authService={authService}
      onLoginSuccess={handleLoginSuccess}
      onLoginError={handleLoginError}
    />
  );
}

3. 使用注册组件

import { RegisterForm } from 'universal-auth';

function App() {
  const handleRegisterSuccess = (user) => {
    console.log('Registration successful:', user);
  };

  const handleRegisterError = (error) => {
    console.error('Registration failed:', error);
  };

  return (
    <RegisterForm
      authService={authService}
      onRegisterSuccess={handleRegisterSuccess}
      onRegisterError={handleRegisterError}
    />
  );
}

4. 使用忘记密码组件

import { ForgotPasswordForm } from 'universal-auth';

function App() {
  const handleResetSuccess = () => {
    console.log('Password reset successful');
  };

  const handleResetError = (error) => {
    console.error('Password reset failed:', error);
  };

  return (
    <ForgotPasswordForm
      authService={authService}
      onSuccess={handleResetSuccess}
      onError={handleResetError}
    />
  );
}

API 文档

AuthService

方法

  • loginWithPhone(params: PhoneLoginParams, options?: LoginOptions): Promise<LoginResponse>
  • loginWithPassword(params: PasswordLoginParams, options?: LoginOptions): Promise<LoginResponse>
  • loginWithEmail(params: EmailLoginParams, options?: LoginOptions): Promise<LoginResponse>
  • loginWithThirdParty(params: ThirdPartyLoginParams, options?: LoginOptions): Promise<LoginResponse>
  • register(params: RegisterParams): Promise<LoginResponse>
  • forgotPassword(params: ForgotPasswordParams): Promise<void>
  • sendVerificationCode(phone: string): Promise<void>
  • sendEmailVerification(email: string): Promise<void>
  • getCaptcha(): Promise<string>
  • logout(): void
  • isAuthenticated(): boolean
  • getCurrentUser(): User | null
  • getToken(): string | null

组件 Props

LoginForm

  • authService: AuthService
  • onLoginSuccess?: (user: User) => void
  • onLoginError?: (error: Error) => void

RegisterForm

  • authService: AuthService
  • onRegisterSuccess?: (user: User) => void
  • onRegisterError?: (error: Error) => void

ForgotPasswordForm

  • authService: AuthService
  • onSuccess?: () => void
  • onError?: (error: Error) => void

样式定制

组件使用 CSS 类名进行样式定义,你可以通过覆盖这些类名来自定义样式:

.login-form,
.register-form,
.forgot-password-form {
  /* 自定义样式 */
}

.login-methods,
.reset-methods {
  /* 自定义样式 */
}

.error-message,
.success-message {
  /* 自定义样式 */
}

贡献

欢迎提交 Issue 和 Pull Request!

许可证

MIT