This repository contains a JWT authentication example with both client-side and server-side setup. The project uses MongoDB for data storage and Gmail for email verification.
Follow these steps to get the project up and running on your local machine.
Ensure you have Node.js installed on your computer.
To clone the repository and access the project folder, run the following commands:
git clone https://github.com/NemoZon/jwt-auth.git
Navigate to the server directory and install the necessary dependencies:
cd ./server
npm install
Create a local environment file for server configuration:
node --eval "fs.writeFileSync('.env.local','')"
Edit the .env.local file by copying the contents from .env and updating the necessary values.
-
Create a MongoDB cluster by signing up or logging into MongoDB.
-
Obtain your MongoDB connection string (format: mongodb+srv://...) and add it to the .env.local file as DB_URL.
To use Gmail as the SMTP service for sending email validations:
-
Replace SMTP_USER with your Gmail address.
-
Replace SMTP_PASSWORD with your app password.
Start the server using:
npm run dev
Navigate to the client directory and install the necessary dependencies:
cd ./client
npm i
Start the client application:
npm start
- Frontend: http://localhost:3000/
- Backend: http://localhost:7000/api