Skip to content

suraj-sella/modern-auth-solution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Modern Authentication Solution

A full-stack MERN application with advanced authentication features including JWT tokens, refresh tokens, and secure session management.

Features

  • User registration and login
  • JWT-based authentication with refresh tokens
  • Protected routes
  • Password change functionality
  • Profile management
  • Modern Material-UI interface
  • Form validation
  • Secure session management

Tech Stack

  • Frontend:

    • React
    • Material-UI
    • Formik & Yup for form validation
    • React Router for navigation
    • Axios for API requests
  • Backend:

    • Node.js
    • Express
    • MongoDB with Mongoose
    • JWT for authentication
    • bcrypt for password hashing
    • Express Validator for input validation

Prerequisites

  • Node.js (v14 or higher)
  • MongoDB
  • npm or yarn

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd modern-auth-solution
  2. Install backend dependencies:

    npm install
  3. Install frontend dependencies:

    cd client
    npm install
  4. Create a .env file in the root directory with the following variables:

    NODE_ENV=development
    PORT=5000
    MONGO_URI=mongodb://localhost:27017/modern-auth
    JWT_SECRET=your_jwt_secret_key_here
    JWT_EXPIRE=1h
    JWT_REFRESH_SECRET=your_jwt_refresh_secret_key_here
    JWT_REFRESH_EXPIRE=7d
    CLIENT_URL=http://localhost:3000
    

Running the Application

  1. Start the backend server:

    npm run server
  2. In a new terminal, start the frontend development server:

    npm run client
  3. The application will be available at:

API Endpoints

Authentication

  • POST /api/auth/register - Register a new user
  • POST /api/auth/login - Login user
  • POST /api/auth/logout - Logout user
  • POST /api/auth/refresh-token - Refresh access token
  • PUT /api/auth/change-password - Change user password

User

  • GET /api/user/me - Get current user profile
  • PUT /api/user/update-profile - Update user profile

Security Features

  • JWT tokens for authentication
  • Refresh tokens for session management
  • Password hashing with bcrypt
  • Protected routes
  • HTTP-only cookies for refresh tokens
  • Input validation
  • CORS configuration
  • Secure password change functionality

Contributing

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

License

This project is licensed under the MIT License.

About

Set up project structure for modern authentication solution

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors