xiaohongshu
xiaohongshu
better-auth-jwt-jwks
Expert skill for implementing Better Auth with JWT tokens and JWKS (JSON Web Key Set) for secure authentication between Next.js frontend and FastAPI backend. Handles JWT token generation, verification, JWKS endpoint setup, and secure API communication. Includes setup for database integration, ses...
Full skill instructions
Better Auth Configuration
JWKS Endpoint Setup (Frontend)
/api/jwks endpoint to expose public keysFastAPI JWT Verification
pyjwt and cryptography dependenciesSecure API Implementation
After activation, I will deliver:
User says: "I have a Next.js 14 App with Better Auth and need to secure my FastAPI backend with JWT tokens."
This Skill Instantly Activates → Delivers:
/api/jwks endpoint in Next.js for public key exposurepyjwt and JWKS clientUser says: "Implement JWT authentication between my Next.js frontend and FastAPI backend."
This Skill Responds: → Sets up Better Auth with JWT generation on frontend → Creates JWKS endpoint for key distribution → Implements JWT verification in FastAPI backend → Provides user isolation and security best practices
import { betterAuth } from "better-auth";
import { jwt } from "better-auth/plugins";
export const auth = betterAuth({
database: {
provider: "postgres",
url: process.env.DATABASE_URL,
},
emailAndPassword: {
enabled: true,
},
plugins: [
jwt({
algorithm: "RS256",
expiresIn: "7d",
issuer: process.env.ISSUER_URL,
}),
],
});
export async function GET() {
const { db } = await import("@/lib/db");
const { jwks } = await import("@/drizzle/schema");
const keys = await db.select().from(jwks);
const jwksResponse = {
keys: keys.map((key) => {
const publicKey = JSON.parse(key.publicKey);
return {
...publicKey,
kid: key.id,
};
}),
};
return new Response(JSON.stringify(jwksResponse), {
status: 200,
headers: {
"Content-Type": "application/json",
"Cache-Control": "public, max-age=3600",
},
});
}
from jwt import PyJWKClient
import jwt
from fastapi import Depends, HTTPException
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
security = HTTPBearer()
def get_jwk_client():
jwks_url = f"{settings.better_auth_url}/.well-known/jwks.json"
return PyJWKClient(jwks_url)
def verify_jwt_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
token = credentials.credentials
try:
jwk_client = get_jwk_client()
signing_key = jwk_client.get_signing_key_from_jwt(token)
payload = jwt.decode(
token,
signing_key.key,
algorithms=["RS256"],
options={"verify_aud": False}
)
user_id = payload.get("sub") or payload.get("user_id")
if not user_id:
raise ValueError("Invalid token: missing user_id")
return {"user_id": user_id, "email": payload.get("email", "")}
except jwt.exceptions.PyJWTError as e:
raise HTTPException(status_code=401, detail=f"Invalid token: {str(e)}")
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience