Better-Auth JWT Skill
Instructions
- •JWT Plugin: Configure the JWT plugin in Better Auth to issue self-contained tokens.
- •Secret Sync: Ensure
BETTER_AUTH_SECRETis identical in both Frontend and Backend environment variables. - •Client Session: Use Better Auth hooks to manage login/logout and retrieve the current token.
- •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();