A Node.js authentication system built with Express, JWT, Passport, Mongoose, and bcrypt. The project supports authentication with Google OAuth 2.0 and includes features like email verification, password reset, and token-based authentication with JWT.
- Local Authentication: Users can register, log in, and authenticate using JWT.
- Google OAuth 2.0: Users can log in using their Google accounts.
- JWT-based Authentication: Secure authentication using access and refresh tokens.
- Email Verification: Users receive an email with a token for account verification.
- Password Reset: Allows users to reset their passwords by sending an email with a reset token.
- Express Sessions: Session management with Express for handling user sessions securely.
- Secure Password Hashing: Uses bcrypt to hash passwords for secure storage.
- Environment Configurations: Easily customizable through
.env
files.
The full API documentation is available on Postman:
Postman - View API Documentation
You can use this to test the different endpoints of the project, such as registration, login, and token-based authentication.
- Node.js (v16 or later)
- MongoDB (local or cloud)
- Google OAuth Credentials (Client ID & Secret)
git clone https://github.com/vatsalpipalava/Nodejs-Authentication.git
cd Nodejs-Authentication
cp .env.example .env
npm install
npm run dev
Method | Endpoint | Description |
---|---|---|
POST | /api/v1/user/register |
Register a new user |
POST | /api/v1/user/login |
Log in with email and password |
POST | /api/v1/user/logout |
Log out from the system |
POST | /api/v1/user/google |
Authenticate with Google OAuth |
Method | Endpoint | Description |
---|---|---|
POST | /api/v1/token/refresh |
Refresh JWT access token |
Method | Endpoint | Description |
---|---|---|
POST | /api/v1/user/verify-email |
Verify user email |
POST | /api/v1/user/forgot-password |
Request password reset link |
POST | /api/v1/user/reset-password |
Reset the user password |