Skip to content

a2rp/backend-httponly-cookie-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

backend-httponly-cookie-auth

Backend authentication API using HttpOnly cookies (no localStorage tokens).

Features

  • Register user
  • Login user
  • Logout user
  • Protected route (get current user)
  • JWT authentication
  • HttpOnly cookie based auth
  • Password hashing using bcrypt
  • MongoDB with Mongoose

Tech Stack

  • Node.js
  • Express.js
  • MongoDB
  • Mongoose
  • JWT
  • bcryptjs
  • cookie-parser

Environment Variables

Create a .env file:

PORT=1198
MONGO_URI=mongodb://127.0.0.1:27017/backend_httponly_cookie_auth
JWT_SECRET=your_secret_key
NODE_ENV=development

Install

npm install

Run

npm run dev

API Endpoints

Register

POST /api/auth/register

{
    "name": "Ashish",
    "email": "ashish@example.com
    ",
    "password": "123456"
}

Login

POST /api/auth/login

{
    "email": "ashish@example.com",
    "password": "123456"
}

Logout

POST /api/auth/logout

Get Current User (Protected)

GET /api/auth/me

Notes

  • Uses HttpOnly cookies for authentication
  • Cookies are automatically handled by browser
  • Use withCredentials: true in frontend

Follow Me

About

Secure backend authentication API using HttpOnly cookies with JWT, built on Node.js, Express, and MongoDB.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors