{"id":29092182,"url":"https://github.com/mohamedaboelnaser/nest-auth","last_synced_at":"2026-04-11T02:01:48.536Z","repository":{"id":300597597,"uuid":"1001091104","full_name":"MohamedAboElnaser/nest-auth","owner":"MohamedAboElnaser","description":"🔐 NestJS authentication system with local login, Google OAuth, JWT tokens, and secure user management","archived":false,"fork":false,"pushed_at":"2025-06-22T15:53:02.000Z","size":223,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-22T16:38:41.942Z","etag":null,"topics":["authentication","docker","jwt","mongodb","mongoose","nestjs","nodejs","oauth2","passport","refresh-tokens","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MohamedAboElnaser.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,"zenodo":null}},"created_at":"2025-06-12T20:05:19.000Z","updated_at":"2025-06-22T15:53:05.000Z","dependencies_parsed_at":"2025-06-22T16:50:33.843Z","dependency_job_id":null,"html_url":"https://github.com/MohamedAboElnaser/nest-auth","commit_stats":null,"previous_names":["mohamedaboelnaser/nest-auth"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MohamedAboElnaser/nest-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MohamedAboElnaser%2Fnest-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MohamedAboElnaser%2Fnest-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MohamedAboElnaser%2Fnest-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MohamedAboElnaser%2Fnest-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MohamedAboElnaser","download_url":"https://codeload.github.com/MohamedAboElnaser/nest-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MohamedAboElnaser%2Fnest-auth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262389457,"owners_count":23303341,"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","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":["authentication","docker","jwt","mongodb","mongoose","nestjs","nodejs","oauth2","passport","refresh-tokens","typescript"],"created_at":"2025-06-28T07:03:38.954Z","updated_at":"2026-04-11T02:01:48.518Z","avatar_url":"https://github.com/MohamedAboElnaser.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NestJS Authentication API\n\nA robust authentication system built with NestJS, featuring multiple authentication strategies including local login and Google OAuth integration.\n\n## Features\n\n- **User Registration \u0026 Login** - Traditional email/password authentication\n- **JWT Authentication** - Access and refresh token implementation\n- **Google OAuth** - Social login integration\n- **Secure Cookies** - HTTP-only cookies for refresh tokens\n- **MongoDB Integration** - User data persistence\n- **Password Hashing** - Secure bcrypt encryption\n- **Input Validation** - Request validation with class-validator\n\n## Authentication Flow\n\nThis application supports two main authentication flows:\n\n### Local Login Flow\n\n![Login Flow](docs/login-flow.png)\n\nThe traditional email/password authentication process includes user registration, login with credentials validation, and JWT token generation.\n\n### Google OAuth Flow\n\n![Google OAuth Flow](docs/Google-Oauth.png)\n\nThe Google OAuth integration allows users to authenticate using their Google accounts through the OAuth 2.0 protocol.\n\n## Quick Start\n\n### Prerequisites\n\n- Node.js (v16 or higher)\n- Docker \u0026 Docker Compose\n- MongoDB (or use the provided Docker setup)\n\n### Installation\n\n1. **Clone the repository**\n\n   ```bash\n   git clone https://github.com/MohamedAboElnaser/nest-auth.git\n   cd nest-auth\n   ```\n\n2. **Install dependencies**\n\n   ```bash\n   npm install\n   ```\n\n3. **Environment Setup**\n\n   _Copy the provided `.env.example` file to your project's root directory and rename it to `.env`. Then, fill in the required values for your environment variables:_\n\n   ```bash\n   cp .env.example .env\n   ```\n\n4. **Start MongoDB with Docker**\n\n   ```bash\n   docker-compose up -d\n   ```\n\n5. **Run the application**\n\n   ```bash\n   # Development mode\n   npm run start:dev\n\n   # Production mode\n   npm run start:prod\n   ```\n\n## API Endpoints\n\n### Authentication\n\n| Method | Endpoint                | Description               |\n| ------ | ----------------------- | ------------------------- |\n| POST   | `/auth/register`        | Register new user         |\n| POST   | `/auth/login`           | Login with email/password |\n| POST   | `/auth/refresh`         | Refresh access token      |\n| GET    | `/auth/google`          | Initiate Google OAuth     |\n| GET    | `/auth/google/callback` | Google OAuth callback     |\n\n### Users\n\n| Method | Endpoint    | Description                       |\n| ------ | ----------- | --------------------------------- |\n| GET    | `/users/me` | Get current user data (protected) |\n\n### General\n\n| Method | Endpoint              | Description             |\n| ------ | --------------------- | ----------------------- |\n| GET    | `/`                   | Health check            |\n| GET    | `/protected-resource` | Test protected endpoint |\n\n## Usage Examples\n\n### Register a new user\n\n```bash\ncurl -X POST http://localhost:4000/auth/register \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"John Doe\",\n    \"email\": \"john@example.com\",\n    \"password\": \"password123\"\n  }'\n```\n\n### Login\n\n```bash\ncurl -X POST http://localhost:4000/auth/login \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"email\": \"john@example.com\",\n    \"password\": \"password123\"\n  }'\n```\n\n### Access protected endpoint\n\n```bash\ncurl -X GET http://localhost:4000/users/me \\\n  -H \"Authorization: Bearer YOUR_ACCESS_TOKEN\"\n```\n\n## Google OAuth Setup\n\n1. Go to [Google Cloud Console](https://console.cloud.google.com/)\n2. Create a new project or select existing one\n3. Enable Google+ API\n4. Create OAuth 2.0 credentials\n5. Add authorized redirect URI: `http://localhost:4000/auth/google/callback`\n6. Copy Client ID and Client Secret to your `.env` file\n\n## Database Management\n\nAccess MongoDB through the web interface:\n\n- **Mongo Express**: http://localhost:8081\n- **Username**: admin\n- **Password**: password\n\n## Scripts\n\n```bash\n# Development\nnpm run start:dev          # Start with hot reload\nnpm run start:debug        # Start in debug mode\n\n# Production\nnpm run build              # Build the application\nnpm run start:prod         # Start production server\n\n# Testing\nnpm run test               # Run unit tests\nnpm run test:e2e           # Run end-to-end tests\nnpm run test:cov           # Run tests with coverage\n\n# Code Quality\nnpm run lint               # Run ESLint\nnpm run format             # Format code with Prettier\n```\n\n## Project Structure\n\n```\nsrc/\n├── auth/                  # Authentication module\n│   ├── strategies/        # Passport strategies\n│   ├── guards/           # Auth guards\n│   └── dtos/             # Data transfer objects\n├── user/                 # User module\n│   ├── schemas/          # MongoDB schemas\n│   └── interfaces/       # TypeScript interfaces\n└── main.ts               # Application entry point\n```\n\n## Tech Stack\n\n- **Framework**: NestJS\n- **Database**: MongoDB with Mongoose\n- **Authentication**: Passport.js (Local, JWT, Google OAuth)\n- **Validation**: class-validator\n- **Password Hashing**: bcrypt\n- **Environment**: dotenv\n\n## License\n\nThis project is [MIT licensed](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohamedaboelnaser%2Fnest-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohamedaboelnaser%2Fnest-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohamedaboelnaser%2Fnest-auth/lists"}