# @better-auth/expo 中文文档

规范地址：https://npmcn.com/package/%40better-auth/expo/

版本：1\.7\.22
npm 元数据更新时间：2026-11-12T09:19:17.580Z
中文译文更新时间：2026-11-12T12:14:57.653Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40better-auth/expo
原文对照：https://npmcn.com/package/%40better-auth/expo/?lang=original
项目主页：https://www.better-auth.com/docs/integrations/expo
源码仓库：https://github.com/better-auth/better-auth

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：52.5 kB，10 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：3 个
- peer 依赖：better-auth ^1\.7\.22，expo-linking \>=7\.0\.0，expo-network \>=8\.0\.7，expo-constants \>=17\.0\.0，expo-web-browser \>=14\.0\.0，@better-auth/core ^1\.7\.22，expo-secure-store \>=12\.5\.0
- 首次发布：2024-11-01T06:22:26.058Z
- 最新版本发布：2026-11-12T09:19:17.202Z
- 近 30 天下载量：6130893（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：605（近 12 个月 171 个）

## 中文简介

更好的 Auth 集成,用于 Expo and React Industrial 应用程序.

## 安装

```sh
npm install @better-auth/expo
```

也可以使用：`pnpm add @better-auth/expo`、`yarn add @better-auth/expo`、`bun add @better-auth/expo`

## README

# 更好的 Auth 博览会插件

此插件将更好的 Auth 与 Expo 集成, 允许您轻松添加 认证您的 Expo( React Industrial) 应用程序 . 它支持博览会本土和网络应用.

## 安装

要启动, 请安装必要的软件包 :

```bash
# Using npm
npm install better-auth @better-auth/expo

# Using yarn
yarn add better-auth @better-auth/expo

# Using pnpm
pnpm add better-auth @better-auth/expo

# Using bun
bun add better-auth @better-auth/expo
```

您还需要安装 `expo-secure-store` 用于安全的会话和饼干 在您的 Expo 应用程序中存储 :

```bash
npm install expo-secure-store
# or
yarn add expo-secure-store
# or
pnpm add expo-secure-store
# or
bun add expo-secure-store
```

## 基本用途

### 配置更好的 Auth 后端

确保设置更好的 Auth 后端 . 你可以跟着主 [安装指南](https://www.better-auth.com/docs/installation)。 。 。 .

然后,将博览会插件添加到您的更好的 Auth 服务器配置中(例如,在  `auth.ts` 或者说 `lib/auth.ts` 文件名 :

```typescript
// lib/auth.ts
import { betterAuth } from 'better-auth';
import { expo } from '@better-auth/expo'; // Import the server plugin

export const auth = betterAuth({
  // ...your other Better Auth options
  baseURL: 'http://localhost:8081', // The base URL of your application server where the routes are mounted.
  plugins: [expo()], // Add the Expo server plugin
  emailAndPassword: {
    enabled: true,
  },
  // Add other configurations like trustedOrigins
  trustedOrigins: ['myapp://'], // Replace "myapp" with your app's scheme
});
```

### 在 Expo 中初始化更好的 Auth 客户端

在您的 Expo app中,初始化客户端( 如: `lib/auth-client.ts`:

```typescript
// lib/auth-client.ts
import { createAuthClient } from 'better-auth/react';
import { expoClient } from '@better-auth/expo/client'; // Import the client plugin
import * as SecureStore from 'expo-secure-store';

export const authClient = createAuthClient({
  baseURL: 'http://localhost:8081', // Your Better Auth backend URL
  plugins: [
    expoClient({
      scheme: 'myapp', // Your app's scheme (defined in app.json)
      storagePrefix: 'myapp', // A prefix for storage keys
      storage: SecureStore, // Pass SecureStore for token storage
    }),
  ],
});

// You can also export specific methods if you prefer:
// export const { signIn, signUp, useSession } = authClient;
```

请确定您的应用方案( 例如“ mayapp ”) 在您的 `app.json`。 。 。 .

## 文档

关于更详细的资料和高级配置,请参考 文档:

-   **主更好的 Auth 安装 :** [安装指南](https://www.better-auth.com/docs/installation)
-   **博览会集成指南:** [博览会融合指南](https://www.better-auth.com/docs/integrations/expo)

## 许可证

麻省理工学院

## 常见问题

### @better-auth/expo 是什么？

更好的 Auth 集成,用于 Expo and React Industrial 应用程序\.

### 如何安装 @better-auth/expo？

在项目目录运行 npm install @better-auth/expo，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：better-auth（^1\.7\.22）、@better-auth/core（^1\.7\.22）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @better-auth/expo 支持 TypeScript 吗？

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

### @better-auth/expo 支持 ESM 还是 CommonJS？

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

### @better-auth/expo 可以商用吗？

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

### @better-auth/expo 的下载量有多少？

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

### @better-auth/expo 还在维护吗？

最新版本 1\.7\.22 发布于 2026/11/12（今天）；至今共发布 605 个版本，其中过去 12 个月发布了 171 个；首次发布于 2024/11/01。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

