← スキル一覧に戻る

jwt
by nimranaz148
⭐ 0🍴 0📅 2026年1月11日
SKILL.md
name: jwt description: JWT (JSON Web Token) patterns for authentication. Use when implementing token-based authentication, verifying tokens, or configuring JWT in Better Auth. allowed-tools: Read, Edit, Write, Glob, Grep, Bash
JWT Skill
Quick Reference
JWT is used for stateless authentication between frontend (Better Auth) and backend (FastAPI).
JWT Structure
Header.Payload.Signature
# Header
{
"alg": "HS256",
"typ": "JWT"
}
# Payload (Claims)
{
"sub": "user_123",
"email": "user@example.com",
"name": "John Doe",
"iat": 1700000000,
"exp": 1700600000
}
# Signature
HMAC-SHA256(header.payload, SECRET)
Better Auth JWT Configuration
// frontend/lib/auth.ts
import { createAuth } from "better-auth"
import { jwt } from "better-auth/plugins"
export const auth = createAuth({
plugins: [
jwt({
jwt: {
secret: process.env.BETTER_AUTH_SECRET!,
expiry: "7d",
},
}),
],
})
Backend JWT Verification (Python)
# backend/auth.py
import jwt
from jwt.exceptions import PyJWTError
BETTER_AUTH_SECRET = os.getenv("BETTER_AUTH_SECRET")
async def verify_jwt(token: str) -> dict:
try:
payload = jwt.decode(
token,
BETTER_AUTH_SECRET,
algorithms=["HS256"]
)
return payload
except PyJWTError as e:
raise HTTPException(status_code=401, detail=f"Invalid token: {e}")
async def get_current_user(credentials) -> str:
payload = await verify_jwt(credentials.credentials)
return payload.get("sub")
Token Claims
| Claim | Meaning |
|---|---|
sub | Subject (user ID) |
email | User email |
name | User name |
iat | Issued at (timestamp) |
exp | Expiration (timestamp) |
iss | Issuer |
aud | Audience |
For Detailed Reference
See REFERENCE.md for:
- Token refresh
- Token revocation
- Security best practices
- Debugging JWT issues
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です