authentication-logic
Better Auth を利用して、クライアント側とサーバー側の認証を適切に行うための方法を分かりやすく解説し、セキュアなシステム構築を支援するSkill。
📜 元の英語説明(参考)
Guide to using Better Auth for client and server-side authentication.
🇯🇵 日本人クリエイター向け解説
Better Auth を利用して、クライアント側とサーバー側の認証を適切に行うための方法を分かりやすく解説し、セキュアなシステム構築を支援するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o authentication-logic.zip https://jpskill.com/download/16935.zip && unzip -o authentication-logic.zip && rm authentication-logic.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/16935.zip -OutFile "$d\authentication-logic.zip"; Expand-Archive "$d\authentication-logic.zip" -DestinationPath $d -Force; ri "$d\authentication-logic.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
authentication-logic.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
authentication-logicフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
認証ロジック
概要
ユーザーの識別には、Better Auth (better-auth) を使用します。
設定
- クライアント:
lib/auth-client.tsはauthClientをエクスポートします。 - サーバー:
lib/auth.tsはauthをエクスポートします。
クライアント側の使用方法
authClient を使用して、クライアントコンポーネントでのサインイン、サインアウト、およびセッション状態の確認を行います。
import { authClient } from "@/lib/auth-client";
// サインイン
await authClient.signIn.email({
email,
password,
});
// ソーシャルサインイン
await authClient.signIn.social({
provider: "google",
callbackURL: "/onboarding",
});
// サインアウト
await authClient.signOut();
サーバー側の使用方法
APIルートまたはサーバーアクションを保護するには、auth.api.getSession を使用します。
import { auth } from "@/lib/auth";
import { headers } from "next/headers";
const session = await auth.api.getSession({
headers: await headers()
});
if (!session) {
return new Response("Unauthorized", { status: 401 });
}
AuthBar コンポーネント
textbook/src/components/AuthBar/index.tsxに配置されています。- ユーザーアバターまたはログインボタンを表示します。
/api/auth/sessionからセッションを取得します (Better Auth をプロキシする Next.js API ルート)。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Authentication Logic
Overview
We use Better Auth (better-auth) for identifying users.
Config
- Client:
lib/auth-client.tsexportsauthClient. - Server:
lib/auth.tsexportsauth.
Client-Side Usage
Use authClient for signing in, signing out, and checking session state in Client Components.
import { authClient } from "@/lib/auth-client";
// Sign In
await authClient.signIn.email({
email,
password,
});
// Social Sign In
await authClient.signIn.social({
provider: "google",
callbackURL: "/onboarding",
});
// Sign Out
await authClient.signOut();
Server-Side Usage
Use auth.api.getSession for protecting API routes or Server Actions.
import { auth } from "@/lib/auth";
import { headers } from "next/headers";
const session = await auth.api.getSession({
headers: await headers()
});
if (!session) {
return new Response("Unauthorized", { status: 401 });
}
AuthBar Component
- Located at
textbook/src/components/AuthBar/index.tsx. - Displays user avatar or login button.
- Fetches session from
/api/auth/session(Next.js API route proxying Better Auth).