{"id":13598462,"url":"https://github.com/marcomelilli/nestjs-email-authentication","last_synced_at":"2025-04-05T03:05:15.996Z","repository":{"id":31399991,"uuid":"127754006","full_name":"marcomelilli/nestjs-email-authentication","owner":"marcomelilli","description":"Nestjs Starter using Mongodb and Passportjs","archived":false,"fork":false,"pushed_at":"2023-02-12T05:00:02.000Z","size":2784,"stargazers_count":487,"open_issues_count":13,"forks_count":108,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-29T02:03:33.930Z","etag":null,"topics":["authentication","email-verification","mongodb","nestjs","passportjs","starter"],"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/marcomelilli.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}},"created_at":"2018-04-02T12:36:00.000Z","updated_at":"2025-03-26T23:59:37.000Z","dependencies_parsed_at":"2023-01-14T19:01:17.995Z","dependency_job_id":"22056c30-7dd4-4301-ae61-3c944a3a9826","html_url":"https://github.com/marcomelilli/nestjs-email-authentication","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcomelilli%2Fnestjs-email-authentication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcomelilli%2Fnestjs-email-authentication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcomelilli%2Fnestjs-email-authentication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcomelilli%2Fnestjs-email-authentication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcomelilli","download_url":"https://codeload.github.com/marcomelilli/nestjs-email-authentication/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280262,"owners_count":20912967,"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","email-verification","mongodb","nestjs","passportjs","starter"],"created_at":"2024-08-01T17:00:52.846Z","updated_at":"2025-04-05T03:05:15.956Z","avatar_url":"https://github.com/marcomelilli.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/marcomelilli","https://img.buymeacoffee.com/button-api/?text=Buy"],"categories":["Resources","资源"],"sub_categories":[],"readme":"# Nestjs email authentication starter\nThis project is an example of implementation of a user **email authentication** with [Nestjs](https://nestjs.com/) v8.4.6, [MongoDB](https://www.mongodb.com/) and [PassportJs](http://www.passportjs.org)\n\nIt can be used as starter for a new project: it implements API for user sign-in/sign-up and features like **email verification**, **forgotten password**, **reset password**, **update profile** and **settings**.\n\n# Getting started\nInstall `nodejs` and `mongodb` in your machine.\n\nInstall dependencies with npm and run the application:\n``` \nnpm install\nnpm run start\n```\n\n# Deploy using Docker\n⚠️ Before deploy the app in a container set the right **configuration** as explained in the section below, and then you can run:\n``` \ndocker-compose up -d\n```\nIt will generate 3 containers: \n- nestjs: nodejs application -\u003e localhost:3000 (you can change the port in the docker-compose.yml)\n- mongodb: database -\u003e expose 27017 in the container network but not reacheable from outside.\n- mongo-express: a web-based MongoDB admin interface -\u003e localhost:8081\n\nYou can edit the config is in `docker-compose.yml`.  \n❗ Note: For security reason, remember to **change the db password** in docker-compose.yml and in config.ts file, and to **change the mongo-express password** to access the console.\n\n\n# Configuration File\nYou can find a `config.ts` file in the root of the project.   \nBefore run the server set your **db configuration** (according you are using docker or not) and your :email: [Nodemailer](https://github.com/nodemailer/nodemailer) options to be able to send emails for registration:\n```\n# Docker Example #\n\"db\": {\n    \"user\": \"root\",\n    \"pass\": \"example\",\n    \"host\": \"mongo\",\n    \"port\": \"27017\",\n    \"database\": \"testdb\", \n    \"authSource\": \"admin\"\n}\n\n# Local nodejs Example #\n\"db\": {\n   \"user\": null,\n   \"pass\": null,\n   \"host\": \"localhost\",\n   \"port\": \"27017\",\n   \"database\": \"testdb\",\n   \"authSource\": null\n}\n\n...  \n\n\"host\": {\n    \"url\": \"\u003cserver-url\u003e\",  //This link is used to redirect users to your server to confirm their email address (link via email)\n    \"port\": \"3000\"\n},\n\n...\n\n\"mail\":{ \n    \"host\": \"\u003csmtp-host\u003e\", //Nodemailer settings (go to the nodemailer documentation for further informations) - You need to set up this to make the signup api start working\n    \"port\": \"\u003cport\u003e\",\n    \"secure\": false,\n    \"user\": \"\u003cusername\u003e\",\n    \"pass\": \"\u003cpassword\u003e\"\n}\n```\n\n# API\nServer will listen on port `3000`, and it expose the following APIs:\n\n\n- **POST** - `/auth/email/register` - Register a new user\n  - **email** - *string*\n  - **password** - *string*\n  - **name** - *string (optional)*\n  - **surname** - *string (optional)*\n\n- **POST** - `/auth/email/login` - Login user\n  - **email** - *string*\n  - **password** - *string*\n\n- **GET** - `/auth/email/verify/:token` - Validates the token sent in the email and activates the user's account\n\n- **GET** - `/auth/email/resend-verification/:email` - Resend verification email\n\n- **GET** - `/auth/email/forgot-password/:email` - Send a token via email to reset the password \n\n- **POST** - `/auth/email/reset-password` - Change user password\n  - **newPassword** - *string*\n  - **newPasswordToken** - *string (token received by forgot-password api)*\n\n- **GET** - `/auth/users` - Returns all users (must be logged in)\n\n- **GET** - `/users/user/:email` - Returns selected user info (must be logged in)\n\n- **POST** - `/users/profile/update` - Update user info\n  - **name** - *string*\n  - **surname** - *string*\n  - **phone** - *string*\n  - **email** - *string*\n  - **birthdaydate** - *Date*\n  - **profilepicture** - *string (base64)*\n\n- **POST** - `/users/gallery/update` -  Add/Remove user photos\n  - **email** - *string*\n  - **action** - *string ('add' or 'remove')*\n  - **newPhoto** - *object* (only for case 'add')\n    - **imageData** - *string (base64)*\n    - **description** - *string*\n  - **photoId** - *string (base64)* (only for case 'remove')\n\n- **POST** - `settings/update` - Update user settings\n  - **email** - *string*\n  - **settingsKey1** - *string (Value1)*\n  - **settingsKey2** - *string (Value2)*\n  - **...**\n  \n\n# Passport JWT strategy\nThis project use JSON Web Token ([JWT](https://www.npmjs.com/package/passport-jwt)) Bearer Token as authentication strategy for Passport. \nThe login API returns an access_token that you have to use to send a correct authorization header in calls that require authentication. You can find an example with postman [here](https://www.getpostman.com/docs/v6/postman/sending_api_requests/authorization)\n\nLogin response:\n```\n{\n   ...\n  \"data\": {\n      \"token\": {\n          \"expires_in\": \"3600\",\n          \"access_token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...._DkYJJh4s\"\n      },\n  ...\n}\n```\n\nAuthorization header example:\n```\n Authorization → Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...._DkYJJh4s\n```\n# Logger\nAll request and response are logged so this can help you to debug in production. \nIf you use pm2 as process manager, I suggest you to install [pm2-logrotate](https://github.com/keymetrics/pm2-logrotate) in your server.\n\n# Security\nThe project implements some of nodejs [security techniques](https://docs.nestjs.com/techniques/security) :\n- [Helmet](https://github.com/helmetjs/helmet) : can help protect your app from some well-known web vulnerabilities by setting HTTP headers appropriately\n- [Express Rate Limit](https://github.com/nfriedly/express-rate-limit): to protect your applications from brute-force attacks\n  - In the main.ts you can set a limit of requests in a time window (default is 100 requests in 15 minutes for all endpoints, and 3 requests in a 1 hour for sign up endpoint)\n\n# Contributing\nIf you want to contribute to this starter, consider:\n\n- Reporting bugs and errors\n- Improve the documentation\n- Creating new features and pull requests\n\n\u003ca href=\"https://www.buymeacoffee.com/marcomelilli\"\u003e\u003cimg src=\"https://img.buymeacoffee.com/button-api/?text=Buy me a coffee\u0026emoji=\u0026slug=marcomelilli\u0026button_colour=FF5F5F\u0026font_colour=ffffff\u0026font_family=Cookie\u0026outline_colour=000000\u0026coffee_colour=FFDD00\"\u003e\u003c/a\u003e\n\nAll contributions are welcome!\n\n# Copyright\nLicensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcomelilli%2Fnestjs-email-authentication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcomelilli%2Fnestjs-email-authentication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcomelilli%2Fnestjs-email-authentication/lists"}