This project is a robust user authentication system offering registration, login, logout, email verification, password reset, and Google authentication, built with modern technologies and security best practices.
MIT License
This project is a comprehensive user authentication system designed to handle various aspects of user authentication, including registration, login, logout, email verification, password reset, and Google authentication. The system is built using modern technologies and follows best practices for security and scalability.
Object-Oriented Programming (OOP):
Inversify Library:
Sign Up page | Sign In page |
Forgot password page | Reset password page |
Email verification page | Dashboard page |
├── server
│ ├── src
│ │ ├── controllers
│ │ │ └── auth
│ │ ├── core
│ │ │ ├── config
│ │ │ └── interfaces
│ │ ├── middlewares
│ │ ├── models
│ │ ├── repositories
│ │ ├── routes
│ │ │ └── auth
│ │ ├── services
│ │ │ └── auth
│ │ ├── utils
│ │ └── validator
│ │ ├── .env.template
│ └── ...
│
├── client
│ ├── src
│ └── ...
│
├── docker-compose.yml
└── README.md
Create a .env
file by copying the .env.template
file and filling in the following environment variables:
PORT=
API_PREFIX=
MONGODB_URI=
SERVER_URL=
CLIENT_URL=
AUTH_ACCESS_TOKEN_SECRET=
AUTH_ACCESS_TOKEN_EXPIRY=
AUTH_REFRESH_TOKEN_SECRET=
AUTH_REFRESH_TOKEN_EXPIRY=
EMAIL_TOKEN_SECRET=
EMAIL_TOKEN_EXPIRY=
AUTH_EMAIL_USER=
AUTH_EMAIL_PASS=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URI=
PORT: Port on which the server will listen.
API_PREFIX: Prefix for all API endpoints.
MONGODB_URI: MongoDB connection URI.
AUTH_ACCESS_TOKEN_SECRET: Secret key for generating access tokens.
AUTH_ACCESS_TOKEN_EXPIRY: Expiry time for access tokens.
AUTH_REFRESH_TOKEN_SECRET: Secret key for generating refresh tokens.
AUTH_REFRESH_TOKEN_EXPIRY: Expiry time for refresh tokens.
EMAIL_TOKEN_SECRET: Secret key for generating email verification tokens.
EMAIL_TOKEN_EXPIRY: Expiry time for email verification tokens.
AUTH_EMAIL_USER: Email address for sending verification emails.
AUTH_EMAIL_PASS: Password for the email account.
GOOGLE_CLIENT_ID: Google OAuth Client ID.
GOOGLE_CLIENT_SECRET: Google OAuth Client Secret.
GOOGLE_REDIRECT_URI: Google OAuth Redirect URI.
http://localhost:3000/auth/google/callback
(or your appropriate redirect URI)..env
file:
GOOGLE_CLIENT_ID
, GOOGLE_CLIENT_SECRET
, and GOOGLE_REDIRECT_URI
environment variables with the values you obtained from Google Cloud Console.Prerequisites:
Clone the repository:
git clone https://github.com/ramo4040/FullStack-User-Authentication-System-TS-React-Express-MongoDB.git
Navigate to the project directory:
cd FullStack-User-Authentication-System-TS-React-Express-MongoDB
Install dependencies:
npm install
Start the containers:
docker-compose up --build -d
This will build the Docker images if they don't exist and then run them in detached mode.
Access the application:
Open your browser and navigate to http://localhost:3000
(or the port specified in your .env
file).
Remember to:
.env
file to version control.Let me know if you have any questions or if there's anything else I can help you with!
POST /api/v1/auth/register
Parameter | Type | Description |
---|---|---|
Username |
string |
Required. User username |
Email |
string |
Required. User email |
Password |
string |
Required. User password |
Confirm password |
string |
Required. User password |
POST /api/v1/auth/login
Parameter | Type | Description |
---|---|---|
email |
string |
Required. User email |
password |
string |
Required. User password |
GET /api/v1/auth/logout
GET /api/v1/auth//google/authenticate
GET /api/v1/auth/google/callback
Parameter | Type | Description |
---|---|---|
code |
query(url) |
callback code |
GET /api/v1/auth//verify-email
Parameter | Type | Description |
---|---|---|
token |
query(url) |
token generated for email validation |
oldAccessToken |
cookies |
old access token |
POST /api/v1/auth/token/refresh
Parameter | Type | Description |
---|---|---|
refreshToken |
cookie(string) |
Required. Refresh token |
POST /api/v1/auth/forgot-password
Parameter | Type | Description |
---|---|---|
email |
string |
Required. User email |
GET /api/v1/auth/validate-reset-token
Parameter | Type | Description |
---|---|---|
token |
query(url) |
Required. Reset token |
PUT /api/v1/auth/reset-password
Parameter | Type | Description |
---|---|---|
token |
query(url) |
Required. Reset token |
email |
string |
Required. New password |
GET /api/v1/auth/me
Notes:
/api/auth/register
, /api/auth/login
, /api/auth/forgot-password
, /api/auth/validate-reset-token
, and /api/auth/google/authenticate
.token
in the request body or query parameter should be a valid authentication or verification token.Contributions are welcome! Please fork the repository, make your changes, and submit a pull request.
This project is licensed under the MIT License.