{"id":30581653,"url":"https://github.com/atharvamhaske/auth_task","last_synced_at":"2025-09-17T23:48:12.714Z","repository":{"id":311460509,"uuid":"1043766011","full_name":"atharvamhaske/AUTH_TASK","owner":"atharvamhaske","description":"This was a assignment Task given by a company where i have to implement backend auth using stack: Hono Prisma NeonDB Postgres also Better Auth and Winston Logger and Telegram BOT also added Swagger UI and Magic link based Login in Better auth.                                        --Atharva","archived":false,"fork":false,"pushed_at":"2025-08-24T19:26:45.000Z","size":81,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-24T20:25:15.827Z","etag":null,"topics":["better-auth","bun","honojs","magiclink","open-source","prisma","swagger-ui","telegrambot"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atharvamhaske.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-08-24T15:19:48.000Z","updated_at":"2025-08-24T19:32:51.000Z","dependencies_parsed_at":"2025-08-24T20:26:14.426Z","dependency_job_id":"50aa7e16-943c-4975-a2ea-feb6b14a771f","html_url":"https://github.com/atharvamhaske/AUTH_TASK","commit_stats":null,"previous_names":["atharvamhaske/auth_task"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/atharvamhaske/AUTH_TASK","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atharvamhaske%2FAUTH_TASK","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atharvamhaske%2FAUTH_TASK/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atharvamhaske%2FAUTH_TASK/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atharvamhaske%2FAUTH_TASK/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atharvamhaske","download_url":"https://codeload.github.com/atharvamhaske/AUTH_TASK/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atharvamhaske%2FAUTH_TASK/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272647131,"owners_count":24969678,"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-29T02:00:10.610Z","response_time":87,"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":["better-auth","bun","honojs","magiclink","open-source","prisma","swagger-ui","telegrambot"],"created_at":"2025-08-29T07:00:52.617Z","updated_at":"2025-09-17T23:48:07.635Z","avatar_url":"https://github.com/atharvamhaske.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Magic Link Authentication Service\n\nA modern authentication service built with Hono, Better-Auth, and PostgreSQL, featuring magic link authentication and comprehensive logging with Telegram bot integration.\n\n## Key Features Showcase\n\n### 1. Magic Link Authentication via POST method\n\u003cimg src=\"docs/images/postReq.png\" alt=\"Swagger UI Screenshot\" width=\"800\"/\u003e\n\n*Interactive API documentation with Swagger UI showing magic link endpoint*\n\n### 2. Real-time Telegram Bot Logging\n\u003cimg src=\"docs/images/TeleBot.png\" alt=\"Telegram Bot Logs\" width=\"800\"/\u003e\n\n*Live authentication monitoring and error tracking through Telegram*\n\nExample log:\n```log\n[25-08-24 00:18] Log: New magic link generated: magic link for test@example.com: \nhttp://localhost:3001/api/auth/magic-link/verify?token=rjvYJzurPuthhqUdzjdkTGawrFrENSMX\u0026callbackURL=%2F\n```\n\n### 3. Checking User using Get method\n\u003cimg src=\"docs/images/getReq.png\" alt=\"User Management Interface\" width=\"800\"/\u003e\n\n*Complete user session tracking and management*\n\n## Project Overview\n\nThis service implements a modern authentication system using magic links with comprehensive logging and monitoring capabilities. Perfect for applications requiring secure, passwordless authentication with full audit trails.\n\n### Authentication Features\n- Passwordless authentication via magic links\n- Secure session management\n- User activity tracking\n- Real-time authentication monitoring\n\n### Logging System\n1. **Winston Logger Integration**\n   - Structured logging with timestamps\n   - Multiple severity levels (INFO, ERROR, WARN)\n   - File-based persistence\n   - Custom formatting\n\n2. **Telegram Bot Integration**\n   ```typescript\n   // Example of Telegram logging setup\n   export async function teleLog(message: string) {\n       const url = `https://api.telegram.org/bot${teleToken}/sendMessage`\n       await fetch(url, {\n           method: \"POST\",\n           body: JSON.stringify({\n               chat_id: chatId,\n               text: `Log: ${message}`,\n               parse_mode: \"Markdown\"\n           })\n       });\n   }\n   ```\n   - Real-time notifications\n   - Authentication event tracking\n   - Error alerting\n   - Security monitoring\n\n3. **Log Categories**\n   - `auth.log`: Authentication attempts\n   - `magic-link.log`: Magic link generation and usage\n   - `error.log`: System errors and failures\n\n## Tech Stack\n\n- **Runtime**: Bun v1.2.18\n- **Framework**: Hono v4.9.4\n- **Authentication**: Better-Auth v1.3.7\n- **Database**: PostgreSQL with Prisma v6.14.0\n- **Logging**: \n  - Winston v3.17.0 for structured logging\n  - Custom Telegram Bot integration\n- **API Documentation**: Swagger UI (@hono/swagger-ui v0.5.2)\n- **Type Safety**: TypeScript v5.9.2\n\n## Project Structure\n\n```\nproject/\n├── docs/                      # Project documentation\n│   ├── images/               # Documentation screenshots\n│   │   ├── getReq.png    # GET method\n│   │   ├── postReq.png  # POST method\n│   │   └── TeleBot.png  #  Telegram bot logging\n│   └── auth-flow-diagram.md  # Authentication flow diagram\n├── prisma/\n│   └── schema.prisma         # Database schema\n├── src/\n│   ├── config/\n│   │   └── logger.ts         # Winston \u0026 Telegram logger setup\n│   ├── docs/\n│   │   └── swagger.ts        # API documentation\n│   ├── lib/\n│   │   └── betterAuth.ts     # Auth configuration\n│   ├── routes/\n│   │   └── auth.ts           # Authentication routes\n│   └── index.ts              # Main application entry\n├── logs/                     # Application logs\n│   ├── app.log              # Combined logs\n│   ├── auth.log             # Authentication logs\n│   └── magic-link.log       # Magic link specific logs\n├── TESTING_GUIDE.md         # Detailed testing instructions\n└── package.json\n```\n\n## Getting Started\n\n1. **Clone and Install**\n   ```bash\n   git clone \u003crepository-url\u003e\n   cd \u003cproject-directory\u003e\n   bun install\n   ```\n\n2. **Environment Setup**\n   ```env\n   DATABASE_URL=\"postgresql://user:password@localhost:5432/dbname\"\n   AUTH_SECRET=\"your-secret-key\"\n   TELE_TOKEN=\"your-telegram-bot-token\"\n   CHAT_ID=\"your-telegram-chat-id\"\n   ```\n\n3. **Database Setup**\n   ```bash\n   bunx prisma generate\n   bunx prisma migrate dev\n   ```\n\n4. **Start Server**\n   ```bash\n   bun run dev:backend\n   ```\n\n5. **Access Points**\n   - Swagger UI: `http://localhost:3001/docs`\n   - Magic Link Endpoint: `POST /auth/magic-link`\n   - Session Check: `GET /auth/session`\n\n## Authentication Flow\n\n```mermaid\nsequenceDiagram\n    participant U as User\n    participant API as API Server\n    participant BA as Better Auth\n    participant DB as Database\n    participant L as Logger\n    participant T as Telegram\n\n    U-\u003e\u003eAPI: POST /auth/magic-link\n    API-\u003e\u003eL: Log request\n    API-\u003e\u003eBA: Request magic link\n    BA-\u003e\u003eDB: Create/Update user\n    BA--\u003e\u003eAPI: Return magic link\n    API-\u003e\u003eL: Log success\n    API-\u003e\u003eT: Send notification\n    API--\u003e\u003eU: Return success message\n```\n\n## Monitoring and Logging\n\n### Winston Logger\n- Structured logging with timestamps\n- Multiple transport layers\n- Error tracking\n- Performance monitoring\n\n### Telegram Bot Integration\n- Real-time notifications\n- Authentication monitoring\n- Error alerts\n- Security event tracking\n\nExample log from Telegram:\n```\n[24-08-25 21:13:11] INFO: Magic link requested for: test@example.com\n[24-08-25 21:13:11] INFO: Magic link generation successful\n```\n\n## Development Notes\n\n- Magic links are logged to console in development\n- Telegram notifications provide real-time monitoring\n- Winston logger handles all system events\n- Complete audit trail of authentication flows","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatharvamhaske%2Fauth_task","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatharvamhaske%2Fauth_task","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatharvamhaske%2Fauth_task/lists"}