This project demonstrates a secure JWT (JSON Web Token) authentication system built with Django, Django Rest Framework (DRF), and React. It includes features like user login, signup, and logout with secure authentication using cookies.
- Signup: Allows users to create an account with email and password.
- Login: Allows users to log in and receive a JWT token stored securely in cookies.
- Logout: Allows users to log out by deleting the JWT token stored in cookies.
- Secure: The JWT token is stored in HTTP-only cookies for enhanced security.
- Backend: Django, Django Rest Framework (DRF)
- Frontend: React.js
- Authentication: JWT (JSON Web Tokens)
- Database: SQLite (or any other database of your choice)
- Security: Cookies (HTTP-Only)
Make sure you have the following installed:
- Python (preferably 3.7+)
- Node.js and npm
- Django
- Django Rest Framework (DRF)
-
Clone the repository.
git clone https://github.com/your-username/Django-React-JWT-Auth.git
-
Navigate to the backend directory.
cd backend
-
Create and activate a virtual environment.
python -m venv venv source venv/bin/activate # On Windows, use venv\Scripts\activate
-
Install required packages.
pip install -r requirements.txt
-
Run migrations to set up the database.
python manage.py migrate
-
Create a superuser (optional) to access the Django admin.
python manage.py createsuperuser
-
Start the Django development server.
python manage.py runserver
-
Navigate to the frontend directory.
cd frontend
-
Install required dependencies.
npm install
-
Start the React development server.
npm start
- Signup: Users can create a new account by entering their email and password. This sends a POST request to the backend, where a JWT token is generated and returned upon successful registration.
- Login: Users can log in using their credentials. On successful authentication, a JWT token is returned and stored in a secure HTTP-only cookie.
- Logout: JWT token is deleted from cookies when the user logs out.
- Implement password reset functionality.
- Add email verification for user signup.
- Improve security with token refresh mechanism.
This project is licensed under the MIT License - see the LICENSE file for details.