Files
container-census/web-next
Self Hosters c91b84bbfc Implement session-based authentication for Next.js frontend
This commit adds complete authentication support to the Next.js frontend,
matching the existing vanilla JS implementation with session-based auth.

Frontend Changes (Next.js):
- Add AuthContext for global auth state management
- Create login page with gradient UI matching vanilla JS design
- Implement ProtectedRoute wrapper for route protection
- Add logout button to Header component
- Move all app pages to (protected)/ route group
- Update API client with improved 401 handling
- Add auth-related TypeScript types

Backend Changes:
- Update static file serving to support both Next.js and vanilla JS
- Add support for /login route (Next.js) in addition to /login.html
- Allow /_next/* routes for Next.js static assets
- Redirect unauthenticated users to /login instead of /login.html

Authentication Flow:
1. User visits app → AuthContext checks session by calling /api/containers
2. If 401 → Redirect to /login page
3. User submits credentials → POST /api/login
4. Backend creates session cookie → Frontend updates context
5. User can access protected routes with valid session
6. Logout destroys session and redirects to login

Key Features:
- Session-based auth with 7-day HTTP-only cookies
- Backward compatible with vanilla JS frontend
- AUTH_ENABLED=false support (skip login entirely)
- XSS protection via HTTP-only cookies
- CSRF protection via SameSite=Lax
- No passwords stored client-side

Files Added:
- web-next/src/contexts/AuthContext.tsx
- web-next/src/app/login/page.tsx
- web-next/src/components/auth/ProtectedRoute.tsx
- web-next/src/app/(protected)/layout.tsx

Files Modified:
- internal/api/handlers.go (static file routing)
- web-next/src/app/layout.tsx (AuthProvider wrapper)
- web-next/src/components/layout/Header.tsx (logout button)
- web-next/src/lib/api.ts (401 handling)
- web-next/src/types/index.ts (auth types)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 12:24:35 -05:00
..

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.

This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.