- Backend uses a controller for routing, a small auth service for credential checks, and a DTO record for the request body.
- The login controller validates input, then delegates to the auth service for the credential check stored in
appsettings.json. - Frontend is a Next.js App Router project with a single client-side
/loginpage for user input and status display. - State is kept local to the login page using React
useStateforloading,token, anderror. - Data flow: user clicks Login -> fetch POSTs to the API -> API returns 200/401/400 -> UI renders Loading, Success, or Error text.
- Tradeoffs: add real JWT signing and secure secret storage; add rate limiting and audit logging for production.
Backend:
cd backend
dotnet restore
dotnet runFrontend:
cd frontend
npm install
npm run devThen visit: http://localhost:3000/login
Tests:
dotnet test backend.TestsBackend:
cd backend
docker build -t minimal-auth-api .
docker run --rm -p 5000:5000 minimal-auth-apiFrontend:
cd frontend
docker build -t minimal-auth-web .
docker run --rm -p 3000:3000 minimal-auth-webDocker Compose (recommended):
docker compose up --buildIf the frontend can't reach the API, verify NEXT_PUBLIC_API_BASE_URL is set to http://localhost:5000 and rebuild.
- Deploy the C# API on Cloud Run for a simple container workflow, autoscaling, and managed HTTPS.
- Deploy the Next.js app on Cloud Run as a separate service so SSR works without extra infrastructure.
- I prefer Kubernetes, deploy the same images to GKE with an Ingress routing
/api/*to the API and/to the web app. - Store images in Artifact Registry and wire Cloud Run/GKE to pull from it.
- CI/CD: run build/test on PRs, build and push images on main, then deploy with a gated release step.
- JWT validation: cache the identity provider JWKS and verify signatures locally.
- Validate issuer and audience claims, and enforce
exp/nbfwith small clock skew. - Refresh JWKS on unknown
kidand reject tokens with unexpected algorithms.
/backend
backend.csproj
Controllers
AuthController.cs
Models
LoginRequest.cs
Program.cs
Services
AuthService.cs
IAuthService.cs
/backend.Tests
AuthServiceTests.cs
backend.Tests.csproj
/frontend
app
login
page.tsx
layout.tsx
page.tsx
next-env.d.ts
next.config.js
package.json
tsconfig.json
docker-compose.yml
README.md