Skip to content

This project is a robust authentication service combining Rust and Node.js with MongoDB for secure user management, password hashing, JWT authentication, and protected routes via Neon bindings and Express.js.

Notifications You must be signed in to change notification settings

kartikmehta8/rust-node-auth-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust-Node Authentication Service

Overview

This project is a robust authentication service that integrates a Rust backend (compiled as a Node.js native module using Neon bindings) with an Express.js server. It uses MongoDB for storing user information and JWT tokens for secure authentication.

Key Features

  • User Registration with password hashing (using bcrypt).
  • Secure Login with JWT generation.
  • Protected routes using JWT verification middleware.
  • MongoDB integration for persistent user data storage.

Endpoints

1. User Registration

  • URL: /signup
  • Method: POST
  • Request Body:
    {
      "name": "John Doe",
      "email": "john.doe@example.com",
      "username": "johndoe",
      "password": "securepassword"
    }
  • Response:
    • Success (201):
      {
        "message": "User registered successfully."
      }
    • Failure (400 or 422):
      {
        "error": "Validation failed: <details>."
      }

2. User Login

  • URL: /login
  • Method: POST
  • Request Body:
    {
      "username": "johndoe",
      "password": "securepassword"
    }
  • Response:
    • Success (200):
      {
        "token": "<jwt-token>"
      }
    • Failure (401):
      {
        "error": "Invalid username or password."
      }

3. Protected Route

  • URL: /protected
  • Method: GET
  • Headers:
    {
      "Authorization": "Bearer <jwt-token>"
    }
  • Response:
    • Success (200):
      {
        "message": "Access granted."
      }
    • Failure (401):
      {
        "error": "Unauthorized."
      }

Environment Variables

Variable Description Default Value
MONGO_URI MongoDB connection string mongodb://localhost:27017
DATABASE_NAME Database name for the project auth_service

About

This project is a robust authentication service combining Rust and Node.js with MongoDB for secure user management, password hashing, JWT authentication, and protected routes via Neon bindings and Express.js.

Topics

Resources

Stars

Watchers

Forks