{"id":25980074,"url":"https://github.com/epic-codebase/django_react_auth","last_synced_at":"2025-08-15T17:11:46.885Z","repository":{"id":277033028,"uuid":"930881025","full_name":"Epic-Codebase/django_react_auth","owner":"Epic-Codebase","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-11T21:26:07.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-05T07:36:27.156Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Epic-Codebase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-11T11:14:16.000Z","updated_at":"2025-02-11T21:26:10.000Z","dependencies_parsed_at":"2025-02-11T19:46:54.364Z","dependency_job_id":null,"html_url":"https://github.com/Epic-Codebase/django_react_auth","commit_stats":null,"previous_names":["epic-codebase/django_react_auth"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Epic-Codebase/django_react_auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Epic-Codebase%2Fdjango_react_auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Epic-Codebase%2Fdjango_react_auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Epic-Codebase%2Fdjango_react_auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Epic-Codebase%2Fdjango_react_auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Epic-Codebase","download_url":"https://codeload.github.com/Epic-Codebase/django_react_auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Epic-Codebase%2Fdjango_react_auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270602456,"owners_count":24614260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-05T07:33:32.481Z","updated_at":"2025-08-15T17:11:46.863Z","avatar_url":"https://github.com/Epic-Codebase.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 django-react-auth\n\nA sample project demonstrating Django DRF authentication using JWT and integrating it with a React frontend. This repository showcases best practices for handling authentication, including token-based authentication, API connections with Axios interceptors, and protected routes in React.\n\n---\n\n## ✨ Features\n\n### 🔹 Backend (Django + DRF)\n- 🔐 **Authentication**: Uses JWT authentication via `djangorestframework-simplejwt`.\n- 🗄️ **Database**: PostgreSQL for robust data storage.\n- 🌍 **CORS Handling**: Configured using `django-cors-headers` to allow frontend API requests.\n- 📡 **REST API**: Built with Django Rest Framework (DRF) to provide secure endpoints.\n\n### 🔹 Frontend (React + Axios)\n- 🔑 **JWT Authentication**: Handles user login, logout, and token storage.\n- ⚡ **Axios Interceptors**: Automatically injects the authorization token into requests.\n- 🔒 **Protected Routes**: Uses a `ProtectedRoute` component to restrict access to authenticated users.\n- 🔄 **Login Page Redirection**: Redirects users to the login page when accessing protected routes if not authenticated or if the token has expired.\n- 🔁 **Automatic Token Refresh**: Axios interceptors attempt to refresh the token before redirecting to login if the access token has expired.\n- ⚙️ **React Hooks \u0026 Context API**: Manages authentication state efficiently.\n\n---\n\n## 🚀 Getting Started\n\n### 📌 Prerequisites\n- 🐍 Python 3.x\n- 🗄️ PostgreSQL\n- 💻 Node.js \u0026 npm/yarn\n\n### 🛠️ Backend Setup\n1. Clone the repository:\n   ```sh\n   git clone https://github.com/yourusername/django-react-auth.git\n   cd django-react-auth/backend\n   ```\n2. Install dependencies using Poetry:\n   ```sh\n   poetry install\n   ```\n3. Configure `.env` file for database settings.\n4. Apply migrations:\n   ```sh\n   poetry run python manage.py migrate\n   ```\n5. Create a superuser:\n   ```sh\n   poetry run python manage.py createsuperuser\n   ```\n6. Run the development server:\n   ```sh\n   poetry run python manage.py runserver\n   ```\n\n### 🎨 Frontend Setup\n1. Navigate to the frontend folder:\n   ```sh\n   cd ../frontend\n   ```\n2. Install dependencies:\n   ```sh\n   npm install  # or yarn install\n   ```\n3. Start the React development server:\n   ```sh\n   npm start  # or yarn start\n   ```\n\n---\n\n🌍 Deploying to Choreo\n\nChoreo makes it easy to deploy your Django and React applications with minimal configuration. Follow these steps to deploy your project:\n\n🔹 Backend Deployment\n\nPush your code to a GitHub repository.\n\nSign in to Choreo.\n\nCreate a new project and select Deploy a Backend Service.\n\nConnect your GitHub repository and choose the Django backend.\n\nConfigure the environment variables (database settings, secret keys, etc.).\n\nDeploy the backend and monitor logs for any issues.\n\n🔹 Frontend Deployment\n\nBuild the React application:\n\nnpm run build\n\nDeploy the frontend using Choreo's Web App Hosting.\n\nLink the frontend to the backend API to complete the deployment.\n\nUse a custom domain or Choreo's provided URL to access your app.\n\n---\n\n## 🔄 API Authentication Flow\n1. 🔑 User logs in and receives an access \u0026 refresh token.\n2. 📥 The access token is stored in memory for requests; the refresh token is stored securely.\n3. 🔄 Axios interceptors automatically append the token to API requests.\n4. ⏳ If the access token expires, Axios attempts to refresh it using the refresh token.\n5. 🚪 If the token refresh fails, the user is redirected to the login page.\n6. 🔒 Protected routes ensure only authenticated users can access certain pages.\n\n---\n\n## 📁 Folder Structure\n```\n├── backend\n│   ├── manage.py\n│   ├── pyproject.toml\n│   ├── poetry.lock\n│   ├── backend (Django project folder)\n│   ├── api (Django app folder)\n│   └── ...\n├── frontend\n│   ├── src\n│   │   ├── components\n│   │   ├── pages\n│   │   ├── styles\n│   │   ├── api.js (Axios instance \u0026 API calls)\n│   │   ├── context (Auth context)\n│   │   └── ...\n│   ├── package.json\n│   └── ...\n└── README.md\n```\n\n---\n\n## 📜 License\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepic-codebase%2Fdjango_react_auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fepic-codebase%2Fdjango_react_auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepic-codebase%2Fdjango_react_auth/lists"}