Skip to content

falsydev/user-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

33 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Authentication System

A comprehensive user management system implementing modern authentication patterns. Features secure user registration, session management, and role-based access control with protected routesโ€”replicating the authentication flows that real applications require.

Demo License React Next.js Firebase


โœจ Features

Core Functionality

  • Complete User Lifecycle: Secure registration, email verification, password management
  • Role-Based Access Control: Admin and user roles with dynamic content visibility
  • Session Management: Protected routes with intelligent redirects and session handling
  • Account Security: Password reset, email change verification, and account recovery flows

Authentication Workflows

  • โœ… User registration with email verification
  • โœ… Secure login/logout with session persistence
  • โœ… Password reset via email with secure token validation
  • โœ… Account recovery when email address is compromised

Dashboard & Profile Management

  • โœ… Role-based content rendering (User vs Admin views)
  • โœ… Profile editing with necessary validation
  • โœ… Email update requiring re-verification
  • โœ… Password change with current password confirmation

Security & User Experience

  • โœ… Protected routes preventing unauthorized access
  • โœ… Unauthenticated routes redirecting logged-in users
  • โœ… Comprehensive error handling with user-friendly messages
  • โœ… Loading states for all asynchronous operations

๐Ÿš€ Tech Stack

  • Frontend: React, Next.js (App Router), Styled Components
  • Backend Services: Firebase Authentication & Firestore Database
  • React Patterns: Context API, Prop Validation, Custom Hooks, Protected Route Components
  • Security Features: Protected routes, role-based rendering, secure session handling
  • Deployment: Vercel

๐Ÿ“ฆ Installation & Setup

  1. Clone the repository:

    git clone https://github.com/falsydev/user-auth.git
    cd user-auth
  2. Install dependencies:

    npm install
  3. Configure environment variables:

    • Copy env.example to .env.local
    • Add your Firebase config values:
    NEXT_PUBLIC_FIREBASE_API_KEY="your_api_key"
    NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN="your_project_id.firebaseapp.com"
    NEXT_PUBLIC_FIREBASE_PROJECT_ID="your_project_id"
    NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET="your_project_id.firebasestorage.app"
    NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID="your_sender_id"
    NEXT_PUBLIC_FIREBASE_APP_ID="your_app_id"
  4. Run the development server:

    npm run dev

    Open http://localhost:3000 to view it in the browser.


๐Ÿ—๏ธ Project Structure

user-auth/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ app/                    # Next.js App Router pages
โ”‚   โ”‚   โ”œโ”€โ”€ dashboard/         # Protected dashboard routes
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ settings/      # User settings pages
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ change-password/
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ edit-profile/
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ update-email/
โ”‚   โ”‚   โ”œโ”€โ”€ login/             # Login page
โ”‚   โ”‚   โ”œโ”€โ”€ signup/            # Registration page
โ”‚   โ”‚   โ”œโ”€โ”€ verify-user/       # Email verifications
โ”‚   โ”‚   โ”œโ”€โ”€ layout.js          # Root layout
โ”‚   โ”‚   โ””โ”€โ”€ page.js            # Home page
โ”‚   โ”œโ”€โ”€ assets/                # Static assets
โ”‚   โ”œโ”€โ”€ components/            # Reusable UI components
โ”‚   โ”œโ”€โ”€ context/               # React Context providers
โ”‚   โ”‚   โ””โ”€โ”€ AuthContext.js     # Authentication state management
โ”‚   โ”œโ”€โ”€ custom-hooks/          # Custom React hooks
โ”‚   โ”‚   โ”œโ”€โ”€ useInterval.js     # Interval management
โ”‚   โ”‚   โ”œโ”€โ”€ useTimeout.js      # Timeout management
โ”‚   โ”‚   โ””โ”€โ”€ useUpdateState.js  # State update utilities
โ”‚   โ”œโ”€โ”€ lib/                   # Utility libraries
โ”‚   โ”‚   โ””โ”€โ”€ firebase.js        # Firebase configuration
โ”‚   โ”‚   โ”œโ”€โ”€ StyledComponentsRegistry.js
โ”‚   โ”œโ”€โ”€ styles/                # Styled Components
โ”‚   โ”‚   โ”œโ”€โ”€ breakpoints.js     # Responsive breakpoints
โ”‚   โ”‚   โ””โ”€โ”€ global.css         # Global styles
โ”‚   โ””โ”€โ”€ utils/                 # Utility functions
โ”‚       โ”œโ”€โ”€ ActionCodeSettings.js
โ”‚       โ”œโ”€โ”€ constants.js       # App constants
โ”‚       โ”œโ”€โ”€ getErrorMessage.js # Error handling
โ”‚       โ”œโ”€โ”€ space.js           # Spacing utilities
โ”‚       โ””โ”€โ”€ validateFormFields.js # Form validation
โ”œโ”€โ”€ .env.local                 # Environment variables (create from .env.example)
โ”œโ”€โ”€ next.config.js             # Next.js configuration
โ””โ”€โ”€ package.json               # Dependencies and scripts

๐Ÿ”ง Configuration

Firebase Setup

  1. Create a Firebase project at Firebase Console

  2. Enable Authentication:

    • Go to Authentication > Sign-in method
    • Enable Email/Password provider
    • Configure authorized domains
  3. Create Firestore Database:

    • Go to Firestore Database
    • Create database in production mode
    • Set up security rules:
rules_version = '2';

service cloud.firestore {
  match /databases/{database}/documents {
   match /users/{userId} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
  }
}
  1. Configure Authentication Settings:
    • Set up email templates for verification and password reset
    • Configure action URLs to point to your application

Environment Variables

Create a .env.local file with your Firebase configuration:

# Firebase Configuration
  NEXT_PUBLIC_FIREBASE_API_KEY="your_api_key"
  NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN="your_project_id.firebaseapp.com"
  NEXT_PUBLIC_FIREBASE_PROJECT_ID="your_project_id"
  NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET="your_project_id.firebasestorage.app"
  NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID="your_sender_id"
  NEXT_PUBLIC_FIREBASE_APP_ID="your_app_id"

๐Ÿ› ๏ธ Development Scripts

# Development
npm run dev          # Start development server
npm run build        # Build for production
npm run start        # Start production server

# Code Quality
npm run lint         # Run ESLint
npm run lint:fix     # Fix ESLint issues

# Deployment
npm run deploy       # Deploy to Vercel

๐Ÿ”’ Security Features

Authentication Security

  • Password Requirements: Minimum 6 characters (Add your complexity on validatePassword() in validateFormFields.js file)
  • Email Verification: Required for account activation
  • Session Management: Secure JWT tokens with automatic refresh
  • Rate Limiting: Built-in Firebase protection against brute force attacks

Data Protection

  • Firestore Security Rules: Server-side data validation and access control
  • Role-Based Access: Dynamic content rendering based on user roles
  • Input Validation: Client and server-side validation for all forms
  • XSS Protection: Sanitized inputs and secure rendering

๐Ÿš€ Deployment

Vercel (Recommended)

  1. Connect your repository to Vercel:

    • Go to vercel.com and sign up/login
    • Click "New Project" and import your GitHub repository
    • Configure environment variables in Vercel dashboard
  2. Set environment variables:

    # In Vercel Dashboard > Project Settings > Environment Variables
    NEXT_PUBLIC_FIREBASE_API_KEY="your_api_key"
    NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN="your_project_id.firebaseapp.com"
    NEXT_PUBLIC_FIREBASE_PROJECT_ID="your_project_id"
    NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET="your_project_id.firebasestorage.app"
    NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID="your_sender_id"
    NEXT_PUBLIC_FIREBASE_APP_ID="your_app_id"
  3. Deploy:

    • Vercel will automatically deploy on every push to main branch
    • Or manually deploy: vercel --prod

Alternative Deployment Options

  • Netlify: Connect repository for automatic deployments
  • Cloudflare Workers: Deploy using Wrangler CLI for edge computing
  • Traditional Hosting: Build with npm run build and deploy static files

๐Ÿ”ฎ Roadmap & Enhancements

Planned Features

  • OAuth Integration: Google, GitHub, and Microsoft sign-in options
  • Two-Factor Authentication: Enhanced security with 2FA implementation
  • PWA Features: Offline functionality and mobile app experience
  • Admin Dashboard: User management with analytics and bulk operations
  • Performance Optimization: Code splitting, lazy loading, and caching strategies

๐Ÿค Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Development Guidelines

  • Follow existing code style and conventions
  • Write tests for new features
  • Update documentation for API changes
  • Ensure all tests pass before submitting PR

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Firebase Team for providing robust authentication services
  • Next.js Team for the excellent React framework
  • React Community for continuous inspiration and best practices
  • Open Source Contributors who make projects like this possible

๐Ÿ“ž Support


Built with โค๏ธ by Saravanan

About

A production-ready, full-stack user authentication prototype built with modern React and Firebase.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors