This project is a robust backend implementation for user authentication, built using Node.js, Express.js, and a configurable database. It provides essential functionalities such as user registration, login, and logout, with secure password hashing using bcrypt and JSON Web Tokens (JWT) (WIP) for session management. This backend can be seamlessly integrated into any web application requiring user authentication.
- User Registration: Allows users to create an account with a unique email address and a securely hashed password.
- User Login: Authenticates users using their email and password, with password hashing implemented using bcrypt.
- JWT Authentication: Provides secure user sessions using JSON Web Tokens.
- Express Routing: Organized routing system implemented using Express.js, separating functionality into dedicated routes for user signup and login.
- Configurable Database: Supports multiple databases. Easily switch between databases by updating the configuration. Currently available databases:
- ✅ Supabase: Open-source Firebase alternative with PostgreSQL.
- ❌ PostgreSQL: Powerful, open-source relational database.
- ❌ MySQL: Popular open-source relational database.
- ❌ SQLite: Lightweight, file-based database.
- ❌ MongoDB: NoSQL database.
Before you begin, ensure you have the following installed:
- Node.js
- pnpm (Package manager)
- Postman or Insomnia (for testing the API)
- A database of your choice (e.g., Supabase, PostgreSQL, MySQL, etc.)
- Clone the Repository:
git clone https://github.com/deep-vinci/login-backend.git
- Install Dependencies:
pnpm install
- Set Up Database:
- Update the
.envfile with your database connection details (e.g., Supabase URL, API key, etc.) and JWT secret key.
- Update the
- Start the Server:
pnpm start
- Signup:
POST http://localhost:3000/signup- Request Body: User data in JSON format (e.g., name, email, password).
- Response: User details with hashed password.
- Login:
POST http://localhost:3000/login- Request Body: User credentials (email and password).
- Response: JWT token for authenticated session.
- Logout:
GET http://localhost:3000/logout- Response: Success message.
Use tools like Insomnia or Postman to test the API endpoints. Ensure you have the correct request body and headers for each endpoint.
- Node.js: JavaScript runtime for building scalable network applications.
- Express.js: Web framework for Node.js.
- Supabase: Open-source Firebase alternative for database and authentication.
- Bcrypt.js: Library for hashing passwords.
- pnpm: Fast, disk-space-efficient package manager.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
For any inquiries or feedback, please reach out to Deepak Jha.
This README provides a comprehensive guide to understanding, setting up, and contributing to the Login Backend project. For more detailed information, refer to the project repository and the linked resources. Happy coding!
Let me know if you need further adjustments!