Skip to content

ivan-luhcyk/iforge_test_task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minimal Login Workflow

Architecture Explanation

  • 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 /login page for user input and status display.
  • State is kept local to the login page using React useState for loading, token, and error.
  • 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.

Run Instructions

Backend:

cd backend
dotnet restore
dotnet run

Frontend:

cd frontend
npm install
npm run dev

Then visit: http://localhost:3000/login

Tests:

dotnet test backend.Tests

Docker

Backend:

cd backend
docker build -t minimal-auth-api .
docker run --rm -p 5000:5000 minimal-auth-api

Frontend:

cd frontend
docker build -t minimal-auth-web .
docker run --rm -p 3000:3000 minimal-auth-web

Docker Compose (recommended):

docker compose up --build

If the frontend can't reach the API, verify NEXT_PUBLIC_API_BASE_URL is set to http://localhost:5000 and rebuild.

GCP Notes

  • 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/nbf with small clock skew.
  • Refresh JWKS on unknown kid and reject tokens with unexpected algorithms.

Folder Structure

/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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors