@base316/react

中文文档
0.8.1发布于 2026/11/07MITTypeScriptESM + CJS近 30 天下载 2068

Drop-in React components for Base316 authentication and billing.

原始使用文档
文档目录6 节
  1. Wrap your app once
  2. Sign in, in your own page
  3. The rest
  4. Styling
  5. White-label for a tenant
  6. Reading the session

@base316/react

Drop-in React components for Base316 — sign-in, sign-up, profile, pricing and billing, rendered inside your own application rather than on a page your users are sent away to.

npm install @base316/react @base316/sdk

Wrap your app once

import { Base316Provider } from "@base316/react";

export default function App({ children }) {
    return (
        <Base316Provider publishableKey={process.env.NEXT_PUBLIC_BASE316_KEY}>
            {children}
        </Base316Provider>
    );
}

The provider holds one client and the signed-in user's session, and fetches the branding you configured in the Base316 dashboard — so what you set there is what these components look like here. No colors to keep in step in two places.

Sign in, in your own page

import { SignIn } from "@base316/react";

export default function LoginPage() {
    return <SignIn onSignedIn={() => router.push("/app")} />;
}

That is the whole integration. No redirect, no popup, no button that sends somebody to another domain and back. Two-factor prompts are handled inside the component when the account has it enrolled.

If you would rather not render sign-in at all, Base316 also hosts the pages — point your users at the link in the dashboard and they come back signed in.

The rest

import {
    UserProfile, // email, password, sessions, two-factor
    PricingTable, // your plans, with a checkout button
    SubscriptionManager, // what they are on, and how to change it
    Invoices, // what they have been billed
    Branding, // your logo and name, as configured
} from "@base316/react";

Styling

Three ways, from least to most invasive. Use the first that works.

1. The dashboard. Whatever you set under Sign-in pages — brand color, background, logo — arrives here automatically.

2. appearance tokens. No CSS to write:

<Base316Provider
  publishableKey={key}
  appearance={{ colorPrimary: "#16a34a", borderRadius: "999px" }}
>

3. Your own CSS, targeting the b316-* class names, or a className on any component to hand it your utility classes.

Every color, radius and font is behind a --b316-* custom property. Nothing inherits your application's styles automatically — silently absorbing whatever body { font } and button { } rules happen to exist produces components that look broken in ways neither side can predict.

White-label for a tenant

When one business runs your product for others — a firm and its clients — show the firm's brand on the screens its clients see:

<Base316Provider publishableKey={key} tenant={{ organizationExternalId: firm.id }}>

The tenant's own branding, then its parent's, then your environment's, field by field. Change tenant when the person switches team and every component restyles. TeamMembers says so when a team is reached through the firm rather than by membership.

Reading the session

import { useSession } from "@base316/react";

function Greeting() {
    const { session, loading } = useSession();

    if (loading) return null;
    return session ? <p>Hello {session.user.email}</p> : <a href="/login">Sign in</a>;
}

loading matters: rendering the signed-out branch first and then swapping makes every page flash a sign-in link at people who are already signed in.

版本与发布记录

@base316/react 共发布 10 个版本,首次发布于 2026/09/13;过去 12 个月发布了 10 个版本。

版本发布日期距今
0.8.1latest2026/11/071 天前
0.8.02026/11/071 天前
0.7.02026/10/299 天前
0.6.02026/10/2612 天前
0.5.22026/10/2217 天前
0.5.12026/10/1920 天前

关于 @base316/react 的常见问题

@base316/react 是什么?

Drop-in React components for Base316 authentication and billing.

如何安装 @base316/react?

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

@base316/react 支持 TypeScript 吗?

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

@base316/react 支持 ESM 还是 CommonJS?

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

@base316/react 可以商用吗?

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

@base316/react 的下载量有多少?

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

@base316/react 还在维护吗?

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