A centralized authentication service for the HackPSU ecosystem, providing secure user authentication and session management across multiple subdomain applications.
The HackPSU Auth Service serves as the single source of truth for user authentication within the HackPSU platform. It provides a unified login experience with support for multiple authentication providers and manages user sessions across all HackPSU subdomain applications through secure session cookies.
Target Users: HackPSU event participants, volunteers, team members, and administrators Primary Use Cases:
- Centralized authentication for hackathon participants
- Role-based access control for HackPSU team members
- Secure session management across multiple applications
- OAuth integration with popular development platforms
Key Capabilities:
- Multi-provider authentication (Email/Password, Google, GitHub, Microsoft)
- JWT-based role verification and access control
- Cross-subdomain session management
- Password reset functionality
- User analytics and tracking integration
- Next.js 15 - Full-stack React framework with App Router for server-side rendering and API routes
- React 19 - Modern UI library with concurrent features and improved performance
- TypeScript - Type-safe development with comprehensive type definitions
- Tailwind CSS 4 - Utility-first CSS framework for rapid UI development
- shadcn/ui - High-quality, accessible React components built on Radix UI primitives
- Radix UI - Unstyled, accessible UI components for complex interactions
- Lucide React - Beautiful, customizable SVG icons optimized for React
- Firebase Authentication - Google's authentication service with multi-provider support
- Firebase Admin SDK - Server-side Firebase operations for session cookie management
- JWT Decode - Client-side JWT token parsing for role extraction and validation
- React Hook Form - Performant forms library with minimal re-renders
- Zod - TypeScript-first schema validation for form data and API responses
- PostHog - Product analytics and user behavior tracking for both client and server-side events
- ESLint - Code linting with Next.js optimized configuration
- Prettier - Consistent code formatting across the codebase
- Hybrid Authentication Flow: Combines Firebase client-side authentication with server-side session cookies
- Multi-Provider Support: OAuth integration with Google, GitHub, and Microsoft for developer convenience
- Role-Based Access Control: JWT custom claims system for fine-grained permission management
- Cross-Domain Sessions: Secure HTTP-only cookies with
.hackpsu.orgdomain for subdomain sharing
- API Routes: RESTful endpoints for session management (
/api/sessionLogin,/api/sessionLogout,/api/sessionUser) - Server Components: Leverage React Server Components for improved performance and SEO
- Client Components: Strategic use of client-side rendering for interactive authentication forms
- Middleware: CORS handling and request preprocessing for cross-origin authentication
- React Context: Centralized authentication state management through
FirebaseProvider - Firebase State Sync: Real-time authentication state synchronization between client and server
- Session Persistence: Automatic session restoration and token refresh handling
- JWT Custom Claims: Role-based permissions encoded in Firebase ID tokens
- CORS Protection: Strict origin validation for HackPSU subdomains only
- Secure Cookies: HTTP-only, secure, SameSite cookies for session management
- Token Validation: Server-side verification of Firebase ID tokens before session creation
- Turbopack: Next.js 15 bundler for faster development builds
- Code Splitting: Automatic route-based code splitting with dynamic imports
- Suspense Boundaries: React Suspense for graceful loading states
- Memoization: Strategic use of React hooks for expensive operations
- Node.js 18+ and Yarn package manager
- Firebase project with Authentication enabled
- Environment variables for Firebase configuration
-
Clone the repository and install dependencies:
git clone <repository-url> cd auth yarn install
-
Configure environment variables:
cp .env.example .env.local # Add your Firebase configuration and service account credentials -
Start the development server:
yarn dev
yarn dev- Start development server with Turbopackyarn build- Create production buildyarn start- Run production serveryarn lint- Run ESLint code analysisyarn format- Format code with Prettier
Required environment variables:
NEXT_PUBLIC_FIREBASE_*- Firebase client configurationFIREBASE_SERVICE_ACCOUNT_*- Firebase Admin SDK credentialsNEXT_PUBLIC_POSTHOG_KEY- PostHog analytics key
src/
├── app/ # Next.js App Router
│ ├── api/ # API route handlers
│ │ ├── sessionLogin/ # Create session cookie
│ │ ├── sessionLogout/ # Clear session cookie
│ │ └── sessionUser/ # Validate session
│ ├── login/ # Authentication pages
│ ├── reset-password/ # Password reset flow
│ ├── layout.tsx # Root layout with providers
│ ├── page.tsx # Home page with auth status
│ └── middleware.ts # CORS and request handling
├── common/
│ ├── config/ # Configuration modules
│ │ ├── environment.ts # Environment variable handling
│ │ └── firebase.ts # Firebase client initialization
│ └── context/
│ └── FirebaseProvider.tsx # Authentication context provider
├── components/
│ └── ui/ # Reusable UI components (shadcn/ui)
└── lib/
├── firebaseAdmin.ts # Firebase Admin SDK setup
└── utils.ts # Utility functions
- Email/Password Authentication - Traditional login with account creation fallback
- OAuth Providers - Google, GitHub, and Microsoft single sign-on
- Password Reset - Secure email-based password recovery
- Account Creation - Automatic user registration for new email addresses
- Cross-Domain Sessions - Secure session sharing across HackPSU subdomains
- Automatic Token Refresh - Transparent JWT token renewal
- Session Validation API - Server-side session verification endpoints
- Secure Logout - Complete session cleanup across all applications
- Responsive Design - Optimized for desktop and mobile devices
- Loading States - Comprehensive loading indicators and error handling
- Return URL Support - Redirect users to intended destination after authentication
- Visual Feedback - Clear success and error messaging
- Type Safety - Comprehensive TypeScript coverage
- Component Library - Consistent UI components with shadcn/ui
- Development Tools - Hot reload, linting, and formatting automation
- Analytics Integration - Built-in user behavior tracking
The application is configured for deployment on Vercel with automatic builds from the main branch. Environment variables must be configured in the deployment platform with the same keys as local development.
- TypeScript: All new code must include proper type definitions
- ESLint: Follow the configured linting rules without exceptions
- Prettier: Use automated formatting for consistent code style
- Component Structure: Follow established patterns for new UI components
- Create feature branches from main
- Ensure all tests pass and linting is clean
- Follow conventional commit message format
- Submit pull requests for code review