Quick Start
Build a working auth backend in 30 lines.
1. Install
pip install 'nexfetch-auth[sqlalchemy,fastapi]'
2. Create the app
app.py
from contextlib import asynccontextmanager
from fastapi import FastAPI
from nexfetch_auth import nexfetch_auth
from nexfetch_auth.db.adapters.sqlalchemy import sqlalchemy_adapter
@asynccontextmanager
async def lifespan(app: FastAPI):
auth = await nexfetch_auth(
secret="change-me-in-production",
database=await sqlalchemy_adapter("sqlite+aiosqlite:///auth.db"),
)
app.mount("/api/auth", auth.app)
yield
await auth.close()
app = FastAPI(lifespan=lifespan)
3. Run
uvicorn app:app --reload
4. Try it
Sign up
curl -X POST http://localhost:8000/api/auth/sign-up/email \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"secure-password","name":"Alice"}'
Sign in
curl -X POST http://localhost:8000/api/auth/sign-in/email \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"secure-password"}' \
-c cookies.txt
Get current session
curl http://localhost:8000/api/auth/get-session -b cookies.txt
Sign out
curl -X POST http://localhost:8000/api/auth/sign-out -b cookies.txt