Skip to content

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.

Notifications You must be signed in to change notification settings

SaiBarathR/jwt-login-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js JWT Authentication Server

A Node.js server providing JWT authentication for a sign-in/sign-up client.

Table of Contents

  1. Introduction
  2. Prerequisites
  3. Installation
  4. Docker
  5. Configuration
  6. API Endpoints
  7. Usage
  8. Client Information
  9. Client Repository
  10. Dependencies
  11. License

Introduction

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.

Prerequisites

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)

Installation

To install and run the server locally, follow these steps:

  1. Clone the repository:

    git clone https://github.com/SaiBarathR/jwt-login-node-service.git
  2. Navigate to the project directory:

    cd jwt-login-node-service
  3. Install dependencies:

    npm install
  4. Start the server:

    npm start

Docker

To run the server using Docker, follow these steps:

  1. Follow the steps 1 & 2 in Installation to clone the repository and navigate to the project directory.

  2. Build the Docker image:

    docker build -t jwt-login-node-service .
  3. Run the Docker container:

    docker run -p 8080:8080 jwt-login-node-service

Configuration

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.

API Endpoints

Authentication Endpoints

  • 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.

User Management Endpoints

  • 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).

Usage

  1. 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).
  2. Sign In

    POST /api/auth/signin

    Parameters:

    • email: User's email.
    • password: User's password.
  3. Google Sign-In

    POST /api/auth/googleSignIn

    Parameters:

    • code: Authorization code from Google OAuth.
  4. Get User Information

    POST /api/userInfo

    Requires authentication.

  5. Delete User Account

    DELETE /api/deleteAccount/:type/:email

    Requires authentication.

Client Information

Dependencies

  • 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.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published