@connect-xyz/auth-react

中文文档
0.84.13发布于 2026/11/04MITTypeScriptES Module零依赖近 30 天下载 2万

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

原始使用文档
文档目录10 节
  1. Requirements
  2. Installation
  3. Getting Started
  4. 1. Import the Auth Component
  5. 2. Add the Auth Component to Your App
  6. 3. Configure Event Callbacks (Optional)
  7. Complete Example
  8. API Reference
  9. Auth Component Props
  10. More Information & Support

@connect-xyz/auth-react

A React SDK that enables frontend React 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.

Requirements

  • React 18.0.0 or higher
  • React DOM 18.0.0 or higher

Installation

npm install @connect-xyz/auth-react

Getting Started

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

1. Import the Auth Component

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

2. Add the Auth Component to Your App

function App() {
  const jwt = 'your-jwt-token'; // Obtain this from your backend authentication

  return (
    <Auth
      jwt={jwt}
      env="production" // or "sandbox" for testing
      theme="auto" // 'auto' (default), 'light', or 'dark'
    />
  );
}

3. Configure Event Callbacks (Optional)

Listen to events from the Auth SDK to handle user interactions:

function App() {
  const jwt = 'your-jwt-token';

  const handleError = ({ errorCode, reason }) => {
    console.log('Auth error occurred:', errorCode, 'Reason:', reason);
  };

  const handleClose = () => {
    console.log('Auth widget closed');
  };

  const handleDeposit = ({ data }) => {
    console.log('Deposit data:', data);
  };

  const handleEvent = ({ type, data }) => {
    console.log('Auth event:', type, 'Data:', data);
  };

  const handleLoaded = () => {
    console.log('Auth widget loaded and ready');
  };

  return (
    <Auth
      jwt={jwt}
      env="production"
      theme="auto" // 'auto' (default), 'light', or 'dark'
      onError={handleError}
      onClose={handleClose}
      onDeposit={handleDeposit}
      onEvent={handleEvent}
      onLoaded={handleLoaded}
    />
  );
}

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

Complete Example

Here's a full example of integrating Connect Auth into your React application:

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

function App() {
  // JWT token should be obtained from your backend
  const jwt = 'your-jwt-token';

  // Choose environment: "production" for live apps, "sandbox" for testing
  const environment = 'production';

  return (
    <div className="App">
      <h1>My Crypto App</h1>

      <Auth
        jwt={jwt}
        env={environment}
        theme="auto" // 'auto' (default), 'light', or 'dark'
        onError={({ errorCode, reason }) => {
          console.log('Error:', errorCode, 'Reason:', reason);
        }}
        onClose={() => {
          console.log('Auth widget closed');
        }}
        onDeposit={({ data }) => {
          console.log('Deposit successful:', data);
        }}
        onEvent={({ type, data }) => {
          console.log('Event type:', type, 'Event data:', data);
        }}
        onLoaded={() => {
          console.log('Auth widget loaded and ready');
        }}
      />
    </div>
  );
}

export default App;

API Reference

Auth Component 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

More Information & Support

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

版本与发布记录

@connect-xyz/auth-react 共发布 98 个版本,首次发布于 2025/10/22;过去 12 个月发布了 93 个版本。

版本发布日期距今
0.84.13latest2026/11/046 天前
0.84.122026/10/3011 天前
0.84.112026/10/2714 天前
0.84.102026/10/2615 天前
0.84.92026/10/2417 天前
0.84.82026/10/2318 天前

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

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

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

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

在项目目录运行 npm install @connect-xyz/auth-react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0)、react-dom(>=18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

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

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

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

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

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

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

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

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

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

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