@connect-xyz/auth-js

中文文档
1.71.13发布于 2026/11/04MITTypeScriptESM + CJS零依赖近 30 天下载 2016

A JavaScript SDK that enables frontend applications to seamlessly integrate with the Connect Auth product.

原始使用文档
文档目录20 节
  1. Installation
  2. Via NPM (recommended)
  3. Via CDN
  4. Getting Started
  5. 1. Import the Auth module
  6. 1.1 Or import via CDN
  7. 2. Initialize the Auth module into Your App
  8. 2.1 Using Typescript (optional)
  9. API Reference
  10. Auth widget Props
  11. Constructor
  12. Methods
  13. Callback Functions
  14. onError
  15. onClose
  16. onDeposit
  17. onEvent
  18. onLoaded
  19. Browser Support
  20. More Information & Support

@connect-xyz/auth-js

A JavaScript SDK that enables frontend applications to seamlessly integrate with the Connect Auth product.

Connect Auth provides a secure, customizable authentication flow for crypto deposits. Learn more in the Connect Auth documentation.

Installation

npm install @connect-xyz/auth-js
import { Auth } from '@connect-xyz/auth-js';

Via CDN

You can import the script in your index file and use the Auth class provided by it.

<script
  type="module"
  src="https://sdk.connect.xyz/auth-web/index.js"
></script>

Or you can directly import in your javascript code.

import { Auth } from 'https://sdk.connect.xyz/auth-web/index.js';

Getting Started

Follow these simple steps to integrate Connect Auth into your frontend application:

1. Import the Auth module

import { Auth } from '@connect-xyz/auth-js';

1.1 Or import via CDN

import { Auth } from 'https://sdk.connect.xyz/auth-web/index.js';

2. Initialize the Auth module into Your App

// Create an Auth instance with configuration
const auth = new Auth({
  jwt: 'your-jwt-token',
  env: 'production', // or 'sandbox'
  theme: 'auto', // 'auto' (default), 'light', or 'dark'
  onError: ({ errorCode, reason }) => {
    console.error('Auth error:', errorCode, 'Reason:', reason);
  },
  onClose: () => {
    console.log('Auth widget closed');
  },
  onDeposit: ({ data }) => {
    console.log('Deposit completed:', data);
  },
  onEvent: ({ type, data }) => {
    console.log('Event received:', type, data);
  },
  onLoaded: () => {
    console.log('Auth widget loaded and ready');
  },
});

// Render the widget to a container element
const container = document.getElementById('auth-container');
await auth.render(container);

// Update configuration dynamically
auth.updateConfig({
  jwt: 'new-jwt-token',
  onError: newErrorHandler,
});

// Check if rendered
if (auth.isRendered()) {
  console.log('Widget is active');
}

// Clean up when done
auth.destroy();

2.1 Using Typescript (optional)

import { Auth, AuthConfig } from '@connect-xyz/auth-js';

const config: AuthConfig = {
  jwt: 'your-jwt-token',
  env: 'sandbox',
  theme: 'dark', // 'auto' (default), 'light', or 'dark'
  onError: ({ errorCode, reason }) => {
    // Handle error with type safety
  },
  onDeposit: ({ data }) => {
    // Handle deposit with type safety
  },
};

const auth = new Auth(config);

API Reference

Auth widget Props

PropTypeRequiredDefaultDescription
jwtstringYes-JWT token for authentication with Connect Auth
env"production" | "sandbox"No"production"Target environment
theme"auto" | "light" | "dark"No"auto"Theme mode for the interface
onError({ errorCode, reason }) => voidNo-Callback for error events
onClose() => voidNo-Callback when the widget is closed
onDeposit({ data }) => voidNo-Callback for deposit received
onEvent({ type, data }) => voidNo-Callback for general events
onLoaded() => voidNo-Callback when the widget is loaded and ready

Constructor

new Auth(config: AuthConfig)

Creates a new Auth instance with the provided configuration.

Parameters

  • config (AuthConfig): Configuration object
    • jwt (string, required): JWT token for authentication
    • env (string, optional): Environment - 'production' (default) or 'sandbox'
    • theme (string, optional): Theme mode - 'auto' (default), 'light', or 'dark'
    • onError (function, optional): Error callback
    • onClose (function, optional): Close callback
    • onDeposit (function, optional): Deposit callback
    • onEvent (function, optional): General event callback
    • onLoaded (function, optional): Callback when widget is loaded and ready

Methods

render(container: HTMLElement): Promise<void>

Renders the Auth widget to the specified container element.

await auth.render(document.getElementById('auth-container'));

updateConfig(config: Partial<AuthConfig>): void

Updates the configuration of an already rendered widget.

auth.updateConfig({
  jwt: 'new-token',
  onError: newErrorHandler,
});

destroy(): void

Removes the widget from the DOM and cleans up resources.

auth.destroy();

isRendered(): boolean

Returns whether the widget is currently rendered.

if (auth.isRendered()) {
  // Widget is active
}

getConfig(): AuthConfig

Returns a copy of the current configuration.

const config = auth.getConfig();
console.log('Current JWT:', config.jwt);

Callback Functions

For detailed information about callback events and their payloads, see the Auth SDK Callbacks documentation.

onError

Called when an error occurs in the Auth widget.

onError: ({ errorCode, reason }) => {
  // errorCode: Error code
  // reason: Human-readable error description
};

onClose

Called when the Auth widget is closed by the user.

onClose: () => {
  // Handle close event
};

onDeposit

Called when a deposit is received.

onDeposit: ({ data }) => {
  // data: Object containing deposit details
};

onEvent

Called for general events from the Auth widget.

onEvent: ({ type, data }) => {
  // type: Event type string
  // data: Event-specific data object
};

onLoaded

Called when the Auth widget has fully loaded and is ready for user interaction. This callback is useful for showing loading states or performing actions once the widget is initialized.

onLoaded: () => {
  // Widget is fully loaded and ready
};

Browser Support

  • Chrome/Edge 90+
  • Firefox 88+
  • Safari 14+
  • All modern browsers with Web Components support

More Information & Support

For comprehensive documentation or support about Connect Auth, visit our Documentation Page.

版本与发布记录

@connect-xyz/auth-js 共发布 95 个版本,首次发布于 2025/10/31;过去 12 个月发布了 91 个版本。

版本发布日期距今
1.71.13latest2026/11/0410 天前
1.71.122026/10/3015 天前
1.71.112026/10/2718 天前
1.71.102026/10/2619 天前
1.71.92026/10/2421 天前
1.71.82026/10/2322 天前

关于 @connect-xyz/auth-js 的常见问题

@connect-xyz/auth-js 是什么?

A JavaScript SDK that enables frontend applications to seamlessly integrate with the Connect Auth product.

如何安装 @connect-xyz/auth-js?

在项目目录运行 npm install @connect-xyz/auth-js,或使用 pnpm add / yarn add / bun add。

@connect-xyz/auth-js 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@connect-xyz/auth-js 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@connect-xyz/auth-js 可以商用吗?

@connect-xyz/auth-js 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@connect-xyz/auth-js 的下载量有多少?

根据 npm 官方下载统计,@connect-xyz/auth-js 在 2026/10/11 – 2026/11/09 这 30 天内被下载 2,016 次,日均约 67 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@connect-xyz/auth-js 还在维护吗?

最新版本 1.71.13 发布于 2026/11/04(10 天前);至今共发布 95 个版本,其中过去 12 个月发布了 91 个;首次发布于 2025/10/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。