Authentication system featuring email verification, password recovery, and welcome emails for a secure and user-friendly experience.
To get a copy of this project up and running on your local machine, follow these steps:
-
Clone the repository:
git clone https://github.com/07SUJITH/AuthFlow.git
-
Navigate to the project directory:
cd AuthFlow
-
Install dependencies:
npm install
-
Set up environment variables: Follow the instructions in the Environment Setup section to create and configure your
.env
file. -
Run the application:
npm start
Your application should now be running on http://localhost:5000
.
To run this project, you will need to add the following environment variables to your .env
file in the root directory of the project.
MONGO_URI=mongodb+srv://<username>:<password>@cluster0.skofr.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0
PORT=5000
JWT_SECRET=your_jwt_secret
NODE_ENV=development
MAILTRAP_API_TOKEN=your_mailtrap_api_token
CLIENT_URL=http://localhost:5173
- MONGO_URI: The connection string for your MongoDB database. Replace
<username>
and<password>
with your MongoDB credentials. - PORT: The port number on which your server will run. Default is
5000
. - JWT_SECRET: A secret key for signing JSON Web Tokens (JWT). Replace
your_jwt_secret
with a strong secret key. - NODE_ENV: The environment in which the application is running. Typically
development
orproduction
. - MAILTRAP_API_TOKEN: Your Mailtrap API token for sending emails. Replace
your_mailtrap_api_token
with your actual Mailtrap API token. - CLIENT_URL: The URL of your frontend application. Default is
http://localhost:5173
.
- Create a
.env
file in the root directory of your project. - Copy the example content above into your
.env
file. - Replace the placeholder values with your actual credentials and configuration.
Currently, this system uses Mailtrap for sending emails. There are some limitations to be aware of:
- Mailtrap Domain: We are using the default Mailtrap domain for sending emails. This means that emails will only be delivered to the email address associated with the Mailtrap API token set in the environment variable
MAILTRAP_API_TOKEN
. - Internal Server Error: If you attempt to send an email to an address that is not associated with the Mailtrap API token, the system will generate an internal server error.
To send emails to all email addresses, you have two options:
-
Buy a Domain and Set Up in Mailtrap:
- Purchase a domain from a domain registrar.
- Set up the domain in Mailtrap by following their domain setup guide.
- Update the environment variable
MAILTRAP_API_TOKEN
with the appropriate API token for your domain.
-
Choose Other Email Services:
- You can choose other email services like SendGrid, Amazon SES, or Mailgun.
- Set up an account with the chosen email service.
- Update your email sending logic and environment variables to use the new service.
If you choose to use SendGrid, you can follow these steps:
-
Sign Up for SendGrid: Create an account on SendGrid.
-
Create an API Key: Generate an API key in the SendGrid dashboard.
-
Update Environment Variables: Add the following environment variables to your
.env
file:SENDGRID_API_KEY=your_sendgrid_api_key
-
Update Email Sending Logic: Modify your email sending logic to use SendGrid. Here is an example
import sgMail from "@sendgrid/mail"; sgMail.setApiKey(process.env.SENDGRID_API_KEY); const sendEmail = async (to, subject, htmlContent) => { const msg = { to, from: "your_verified_email@example.com", // Use the email address you verified with SendGrid subject, html: htmlContent, }; await sgMail.send(msg); };