A Node.js server providing JWT authentication for a sign-in/sign-up client.
- Introduction
- Prerequisites
- Installation
- Docker
- Configuration
- API Endpoints
- Usage
- Client Information
- Client Repository
- Dependencies
- License
This Node.js authentication server is designed to provide JWT authentication for a sign-in/sign-up client. It includes Google Sign-In integration, manual sign-up/sign-in, and user management features. The server is built using Node.js, Express, Sequelize, and PostgreSQL. It is designed to be used with a CORS-enabled client application. The client application can be found here.
Ensure you have the following software installed on your machine:
- Node.js
- npm (Node Package Manager)
- PostgreSQL (as per the configuration, you can modify it for other databases)
- Google API key and OAuth credentials (see Google Sign-In for more information)
- A CORS-enabled client application (see Client Information)
To install and run the server locally, follow these steps:
-
Clone the repository:
git clone https://github.com/SaiBarathR/jwt-login-node-service.git
-
Navigate to the project directory:
cd jwt-login-node-service
-
Install dependencies:
npm install
-
Start the server:
npm start
To run the server using Docker, follow these steps:
-
Follow the steps 1 & 2 in Installation to clone the repository and navigate to the project directory.
-
Build the Docker image:
docker build -t jwt-login-node-service .
-
Run the Docker container:
docker run -p 8080:8080 jwt-login-node-service
Create a .env
file in the root directory of the project and add the following environment variables:
GOOGLE_CLIENT_ID= # Google client ID for OAuth.
GOOGLE_CLIENT_SECRET= # Google client secret for OAuth.
GOOGLE_API_KEY= # Google API key.
AUTH_SECRET= # Secret key for JWT authentication.
CORS_URLS= # Comma-separated list of allowed CORS URLs.
MODE= # Development mode.
Configure the PostgreSQL database settings in the environment variables as follows:
DB_HOST= # Database host.
DB_USER= # Database user.
DB_PASS= # Database password.
DB_NAME= # Database name.
DB_DIALECT= # Database dialect.
- POST /api/auth/signup: Register a new user.
- POST /api/auth/signin: Sign in with email and password.
- POST /api/auth/googleSignIn: Sign in/register with Google.
- GET /api/test/all: Public content.
- GET /api/test/user: User content (requires authentication).
- POST /api/userInfo: Get user information (requires authentication).
- DELETE /api/deleteAccount/:type/:email: Delete user account (requires authentication).
-
Sign Up
POST /api/auth/signup
Parameters:
email
: User's email.password
: User's password (optional).name
: User's name.age
: User's age.gender
: User's gender.photo
: User's photo URL (optional).
-
Sign In
POST /api/auth/signin
Parameters:
email
: User's email.password
: User's password.
-
Google Sign-In
POST /api/auth/googleSignIn
Parameters:
code
: Authorization code from Google OAuth.
-
Get User Information
POST /api/userInfo
Requires authentication.
-
Delete User Account
DELETE /api/deleteAccount/:type/:email
Requires authentication.
bcryptjs
: Password hashing.cors
: Cross-Origin Resource Sharing.dotenv
: Environment variable management.express
: Web application framework.google-auth-library
: Google OAuth library.jsonwebtoken
: JSON Web Token implementation.node-fetch
: HTTP requests.nodemon
: Development server auto-restart.pg
: PostgreSQL client for Node.js.sequelize
: SQL ORM for Node.js.
This project is licensed under the MIT License - see the LICENSE file for details.