Better Auth 用 React ログイン UI:2FA 付きサインイン、サインアップ、ソーシャルボタン、フック
コード6 ファイルコンテキスト約 468 トークンスキャン合格
インストール
$
genpm add @yohangel/auth-react含まれるもの
- src/lib/auth-react/ にソースコード(6 ファイル)。 (10.4 KB)
- src/lib/auth-react/AGENTS.md に AI ルール、加えて IDE 用のルールファイル。
README
このパッケージには README がありません。
約 468 トークン→ src/lib/auth-react/AGENTS.md→ .cursor/rules/genpm-yohangel-auth-react.mdc
これは AI が src/lib/auth-react で作業するときに読む内容そのものです。それ以外はコンテキストに追加されません。
@yohangel/auth-react — rules for AI agents
Purpose
React client for a server running @yohangel/auth (Next.js, Express, NestJS…): useSession, unstyled accessible forms (sign-in with TOTP second step, sign-up, social buttons) and UI guards. Client-only; it never decides access by itself.
Module map
index.ts— public API.client.ts—authClient(Better Auth React client + 2FA plugin),useSession,signIn,signUp,signOut,AUTH_BASE_URL.forms.tsx—SignInForm,SignUpForm,SocialButtons,defaultLabels/AuthLabels.guard.tsx—SignedIn(render with/without session),SignOutButton.
Integration (do this after installing)
- Same origin as the API (Next.js, or SPA served by the same server): nothing to configure.
- API on another origin: set
AUTH_BASE_URLinclient.tsto the API URL, add this app's origin toAUTH_TRUSTED_ORIGINSon the server, and enable CORS withcredentials: truethere. - Pages:
<SignInForm redirectTo="/dashboard" />,<SignUpForm redirectTo="/welcome" />,<SocialButtons providers={['github']} />(only providers configured on the server). - In Next.js these are Client Components: put
'use client'in the file that renders them. - Translate by passing
labels={{ signIn: '…', password: '…' }}; style viaclassNameand the[data-auth-error]attribute.
Conventions
- Use
useSession()for UI state only (show name, hide buttons). Every protected API/page must check the session on the server. - Keep the password
minLengthin sync with the server (12).
Don't
- Don't store tokens in
localStorage/sessionStorage: the session lives in an HttpOnly cookie managed by Better Auth. - Don't pass absolute URLs from query params to
redirectTo(the components only follow internal paths). - Don't log form values or errors that may contain the password.
# @yohangel/auth-react — rules for AI agents
## Purpose
React client for a server running `@yohangel/auth` (Next.js, Express, NestJS…): `useSession`, unstyled accessible forms (sign-in with TOTP second step, sign-up, social buttons) and UI guards. Client-only; it never decides access by itself.
## Module map
- `index.ts` — public API.
- `client.ts` — `authClient` (Better Auth React client + 2FA plugin), `useSession`, `signIn`, `signUp`, `signOut`, `AUTH_BASE_URL`.
- `forms.tsx` — `SignInForm`, `SignUpForm`, `SocialButtons`, `defaultLabels` / `AuthLabels`.
- `guard.tsx` — `SignedIn` (render with/without session), `SignOutButton`.
## Integration (do this after installing)
1. Same origin as the API (Next.js, or SPA served by the same server): nothing to configure.
2. API on another origin: set `AUTH_BASE_URL` in `client.ts` to the API URL, add this app's origin to `AUTH_TRUSTED_ORIGINS` on the server, and enable CORS with `credentials: true` there.
3. Pages: `<SignInForm redirectTo="/dashboard" />`, `<SignUpForm redirectTo="/welcome" />`, `<SocialButtons providers={['github']} />` (only providers configured on the server).
4. In Next.js these are Client Components: put `'use client'` in the file that renders them.
5. Translate by passing `labels={{ signIn: '…', password: '…' }}`; style via `className` and the `[data-auth-error]` attribute.
## Conventions
- Use `useSession()` for UI state only (show name, hide buttons). Every protected API/page must check the session on the server.
- Keep the password `minLength` in sync with the server (12).
## Don't
- Don't store tokens in `localStorage`/`sessionStorage`: the session lives in an HttpOnly cookie managed by Better Auth.
- Don't pass absolute URLs from query params to `redirectTo` (the components only follow internal paths).
- Don't log form values or errors that may contain the password.
.genpmignore 適用後に組み込まれる正確なツリーです。固定先:
MIT License
Copyright (c) 2026 Yohangel
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
このパッケージは MCP サーバーを宣言していません。
| バージョン | コミット | 公開日 | スキャン |
|---|---|---|---|
| 1.0.0 | 7145b9d | 4 時間前 | ✔ スキャン合格 |
- genpm
- なし
- 提案
- GenPM は npm コマンドを提案し、あなたが承認した場合にのみ実行します。
- スキャン
- スキャン合格 · 指摘 0 件
- コミット
- auth-react@1.0.0 → 7145b9d58055b5145085782c958b7577f1d65276 · 取得後に検証済み
- スクリプト
- なし。GenPM はパッケージのコードを実行しません。
- ライセンス
- MIT
- 報告
- 問題を見つけましたか?