Skip to content
Skill

better-auth-skill

by WajahatAli3218664

AI Summary

A practical guide for integrating Better Auth with JWT tokens in FastAPI backends and TypeScript frontends, helping developers implement secure authentication quickly with proper project structure and configuration examples.

Install

Copy this and paste it into Claude Code, Cursor, or any AI assistant:

I want to install the "better-auth-skill" skill in my project.

Please run this command in my terminal:
# Install skill into the correct directory (9 files)
mkdir -p .claude/skills/skills && curl --retry 3 --retry-delay 2 --retry-all-errors -o .claude/skills/skills/SKILL.md "https://raw.githubusercontent.com/WajahatAli3218664/Hackathon-02-mytodo/main/.claude/skills/better-auth-skill.SKILL.md" && curl --retry 3 --retry-delay 2 --retry-all-errors -o .claude/skills/skills/README.md "https://raw.githubusercontent.com/WajahatAli3218664/Hackathon-02-mytodo/main/.claude/skills/README.md" && curl --retry 3 --retry-delay 2 --retry-all-errors -o .claude/skills/skills/fastapi-backend-skill.SKILL.md "https://raw.githubusercontent.com/WajahatAli3218664/Hackathon-02-mytodo/main/.claude/skills/fastapi-backend-skill.SKILL.md" && curl --retry 3 --retry-delay 2 --retry-all-errors -o .claude/skills/skills/groq-inference-skill.SKILL.md "https://raw.githubusercontent.com/WajahatAli3218664/Hackathon-02-mytodo/main/.claude/skills/groq-inference-skill.SKILL.md" && curl --retry 3 --retry-delay 2 --retry-all-errors -o .claude/skills/skills/mcp-tools-skill.SKILL.md "https://raw.githubusercontent.com/WajahatAli3218664/Hackathon-02-mytodo/main/.claude/skills/mcp-tools-skill.SKILL.md" && curl --retry 3 --retry-delay 2 --retry-all-errors -o .claude/skills/skills/nextjs-frontend-skill.SKILL.md "https://raw.githubusercontent.com/WajahatAli3218664/Hackathon-02-mytodo/main/.claude/skills/nextjs-frontend-skill.SKILL.md" && curl --retry 3 --retry-delay 2 --retry-all-errors -o .claude/skills/skills/openai-chatkit-skill.SKILL.md "https://raw.githubusercontent.com/WajahatAli3218664/Hackathon-02-mytodo/main/.claude/skills/openai-chatkit-skill.SKILL.md" && curl --retry 3 --retry-delay 2 --retry-all-errors -o .claude/skills/skills/spec-driven-workflow-skill.SKILL.md "https://raw.githubusercontent.com/WajahatAli3218664/Hackathon-02-mytodo/main/.claude/skills/spec-driven-workflow-skill.SKILL.md" && curl --retry 3 --retry-delay 2 --retry-all-errors -o .claude/skills/skills/sqlmodel-database-skill.SKILL.md "https://raw.githubusercontent.com/WajahatAli3218664/Hackathon-02-mytodo/main/.claude/skills/sqlmodel-database-skill.SKILL.md"

Then restart Claude Code (or reload the window in Cursor) so the skill is picked up.

Description

Configure Better Auth with JWT for secure authentication

Instructions

This skill provides guidance for configuring Better Auth with JWT for secure user authentication.

Project Structure

` backend/ ├── auth/ │ ├── __init__.py │ ├── service.py # Auth business logic │ ├── dependencies.py # FastAPI dependencies │ ├── routes.py # Auth endpoints │ └── schemas.py # Pydantic schemas frontend/ └── src/ ├── lib/ │ └── auth.ts # Frontend auth utilities └── hooks/ └── useAuth.ts # Auth state hook `

backend/auth/config.py

from pydantic_settings import BaseSettings from datetime import timedelta from typing import Optional class AuthSettings(BaseSettings): SECRET_KEY: str ALGORITHM: str = "HS256" ACCESS_TOKEN_EXPIRE_MINUTES: int = 30 REFRESH_TOKEN_EXPIRE_DAYS: int = 7 class Config: env_file = ".env" env_file_encoding = "utf-8" auth_settings = AuthSettings() `

backend/auth/service.py

from datetime import datetime, timedelta from typing import Optional from jose import JWTError, jwt from passlib.context import CryptContext from models.user import User from database import AsyncSessionLocal from sqlalchemy import select from fastapi import Depends, HTTPException, status from fastapi.security import OAuth2PasswordBearer pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/v1/auth/login") ALGORITHM = "HS256" ACCESS_TOKEN_EXPIRE_MINUTES = 30 def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str: """Create JWT access token.""" to_encode = data.copy() if expires_delta: expire = datetime.utcnow() + expires_delta else: expire = datetime.utcnow() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) to_encode.update({"exp": expire}) encoded_jwt = jwt.encode( to_encode, auth_settings.SECRET_KEY, algorithm=ALGORITHM ) return encoded_jwt def create_refresh_token(data: dict) -> str: """Create JWT refresh token.""" to_encode = data.copy() expire = datetime.utcnow() + timedelta(days=7) to_encode.update({"exp": expire, "type": "refresh"}) return jwt.encode(to_encode, auth_settings.SECRET_KEY, algorithm=ALGORITHM) def verify_password(plain_password: str, hashed_password: str) -> bool: """Verify password against hash.""" return pwd_context.verify(plain_password, hashed_password) def hash_password(password: str) -> str: """Hash password for storage.""" return pwd_context.hash(password) async def authenticate_user(email: str, password: str) -> Optional[User]: """Authenticate user by email and password.""" async with AsyncSessionLocal() as db: result = await db.execute( select(User).where(User.email == email) ) user = result.scalar_one_or_none() if not user: return None if not verify_password(password, user.hashed_password): return None return user async def get_user_by_email(email: str) -> Optional[User]: """Get user by email.""" async with AsyncSessionLocal() as db: result = await db.execute( select(User).where(User.email == email) ) return result.scalar_one_or_none() async def create_user(email: str, password: str, name: str) -> User: """Create new user.""" async with AsyncSessionLocal() as db: hashed_password = hash_password(password) user = User( email=email, hashed_password=hashed_password, name=name ) db.add(user) await db.commit() await db.refresh(user) return user `

Discussion

0/2000
Loading comments...

Health Signals

MaintenanceCommitted 2mo ago
Active
AdoptionUnder 100 stars
0 ★ · Niche
DocsMissing or thin
Undocumented

GitHub Signals

Issues0
Updated2mo ago
View on GitHub
No License

My Fox Den

Community Rating

Sign in to rate this booster

Works With

Claude Code