PRODIGY_FS_01 Tailwind Templates

Prodigy_fs_01

A modern, secure, and user-friendly authentication system built with Next.js, Tailwind CSS, and MongoDB.

Next.js Authentication System

A modern, secure, and user-friendly authentication system built with Next.js, Tailwind CSS, and MongoDB.

Features

  • User registration with email and password
  • Secure login with JWT authentication
  • Protected routes and role-based access control
  • Responsive design optimized for both desktop and mobile
  • Custom UI components for consistent styling
  • Server-side rendering for improved performance and SEO

šŸ“ø Screenshots

Login Page

Registration Page

Dashboard

šŸ› ļø Technologies Used

šŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

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

šŸš€ Getting Started

  1. Clone the repository:
git clone https://github.com/wassimOubaziz/PRODIGY_FS_01.git
  1. Install dependencies:
npm install

or

yarn install
  1. Set up environment variables: Create a .env.local file in the root directory and add the following:
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
  1. Run the development server:
npm run dev

or

yarn dev
  1. Open http://localhost:3000 in your browser to see the application.

šŸ“ Project Structure

src/
ā”œā”€ā”€ app/
│   ā”œā”€ā”€ page.js
│   ā”œā”€ā”€ layout.js
│   └── globals.css
ā”œā”€ā”€ pages/
│   ā”œā”€ā”€ api/
│   │   └── auth/
│   │       ā”œā”€ā”€ login.js
│   │       ā”œā”€ā”€ register.js
│   │       └── logout.js
│   ā”œā”€ā”€ login.js
│   ā”œā”€ā”€ register.js
│   └── dashboard.js
ā”œā”€ā”€ components/
│   ā”œā”€ā”€ Layout.js
│   ā”œā”€ā”€ Navbar.js
│   ā”œā”€ā”€ ClientNavbar.js
│   ā”œā”€ā”€ AuthForm.js
│   ā”œā”€ā”€ Button.js
│   └── Input.js
ā”œā”€ā”€ lib/
│   ā”œā”€ā”€ mongodb.js
│   └── auth.js
ā”œā”€ā”€ models/
│   └── User.js
└── middleware/
└── authMiddleware.js

šŸ”’ Authentication Flow

  1. Registration: Users can create an account by providing a username, email, and password. Passwords are hashed using bcrypt before being stored in the database.

  1. Login: Users can log in using their email and password. Upon successful authentication, a JWT token is generated and stored in the browser's local storage.

  2. Protected Routes: Certain routes (e.g., dashboard) are protected and can only be accessed by authenticated users. The JWT token is used to verify the user's identity.

https://github.com/user-attachments/assets/3d9230f4-bfe6-4306-b150-c7a8cf09ca93

  1. Logout: Users can log out, which removes the JWT token from local storage and redirects them to the login page.

šŸŽØ UI Components

  • Button: A reusable button component with consistent styling.
  • Input: A styled input component for form fields.
  • AuthForm: A flexible form component used for both login and registration.
  • Navbar: A responsive navigation bar with dynamic content based on authentication status.

šŸ” Security Considerations

  • Passwords are hashed using bcrypt before storage.
  • JWT tokens are used for maintaining user sessions.
  • Protected routes are implemented using middleware to verify authentication.
  • CORS is configured to restrict access to the API.
  • Rate limiting is implemented to prevent brute-force attacks.

šŸš€ Deployment

This application can be easily deployed to platforms like Vercel or Netlify. Make sure to set up the required environment variables in your deployment platform.

šŸ¤ Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

šŸ“ License

This project is MIT licensed.

šŸ‘¤ Author

Wassim Oubaziz

šŸ™ Acknowledgements

Top categories

Loading Svelte Themes