@visiblebase/service-accounts
v0.1.12
Published
VisibleBase accounts service — registration, login, email verification, GitHub/Google OAuth via better-auth.
Maintainers
Readme
@visiblebase/service-accounts
VisibleBase 官方账号管理服务。
安装
pnpm add @visiblebase/service-accounts使用
import { Base } from "@visiblebase/core";
import { accountsService } from "@visiblebase/service-accounts";
const base = new Base({
services: [
accountsService({
token_ttl: "7d",
}),
],
});服务会自动维护两层数据:
better-auth认证事实表:auth_users、auth_accounts、auth_sessions、auth_verifications- 产品资料表:
auth_profiles - OAuth 轮询 state 表:
service_accounts_oauth_states
Base 使用者不需要自己手写这些表;产品真正要展示的资料建议直接读服务提供的 profile 结果。
路由
POST /v1/accounts/registerPOST /v1/accounts/verify-emailPOST /v1/accounts/loginGET /v1/accounts/providersPOST /v1/accounts/oauth/startGET /v1/accounts/oauth/resultGET /v1/accounts/oauth/callbackGET /v1/accounts/mePOST /v1/accounts/logoutGET /v1/accounts/usersGET /v1/accounts/sessions
注册或登录请求传入 product_id 后,服务会返回 Base user_token。
第三方 OAuth 的回调地址固定为 /v1/accounts/oauth/callback。调用 oauth/start 时不需要额外传 redirect_uri,服务会根据当前 Base 的公网地址自动生成。
GET /v1/accounts/me 会返回两部分:
user:当前 Baseuser_token解析出的运行时用户profile:产品层资料,例如展示名、头像
GET /v1/accounts/users 给管理侧看认证用户与 profile 汇总数据。
产品前端、CLI 或其他 client 如果要决定当前应该展示哪些登录按钮,应该先调用:
GET /v1/accounts/providers这个接口会返回当前 Base 实际启用的登录方式,例如邮箱登录、GitHub OAuth、Google OAuth 是否真的可用。不要在 client 里把 provider 列表写死。
