AgentSkillsCN

better-auth-jwt-skill

在配置身份验证流程,或在前后端之间处理身份令牌时使用。

SKILL.md
--- frontmatter
name: better-auth-jwt-skill
description: Use when configuring authentication flows or handling identity tokens between frontend and backend.

Better-Auth JWT Skill

Instructions

  1. JWT Plugin: Configure the JWT plugin in Better Auth to issue self-contained tokens.
  2. Secret Sync: Ensure BETTER_AUTH_SECRET is identical in both Frontend and Backend environment variables.
  3. Client Session: Use Better Auth hooks to manage login/logout and retrieve the current token.
  4. Token Refresh: Handle token expiration by guiding the user back to the login flow if the session dies.

Examples

  • Plugin Config: plugins: [ jwt({ secret: process.env.BETTER_AUTH_SECRET }) ]
  • Client Hook: const { data: session } = authClient.useSession();