a simple and secure authentication system for node.js applications. handle user registration, login, and session management with ease.
- jwt authentication - secure token-based authentication
- sqlite database - lightweight and file-based storage
- rate limiting - prevent brute force attacks
- security - helmet.js, csrf protection, and secure headers
- simple api - easy to integrate with any frontend
- lightweight - minimal dependencies
- node.js 18+ (lts recommended)
- npm 9+ or yarn 1.22+
- sqlite (file-based, no separate installation needed)
-
clone the repository:
git clone https://github.com/hdhw/scriptauth.git cd scriptauth -
install dependencies:
npm install
-
set up environment variables:
cp .env.example .env # edit .env with your configuration -
start the development server:
npm run dev
-
open your browser to http://localhost:3000
.
├── backend/ # server-side code
│ ├── auth/ # authentication logic
│ ├── db/ # database connection and models
│ └── routes/ # api routes
├── public/ # static files (css, js, images)
├── views/ # ejs templates
├── .env.example # example environment variables
└── package.json
copy .env.example to .env and update the values:
# server
node_env=development
port=3000
# jwt
jwt_secret=your_jwt_secret_key_here
jwt_expires_in=24h
# database
database_url=sqlite:./data/auth.db
# security
cors_origin=http://localhost:3000
rate_limit_window_ms=900000
rate_limit_max=100
trust_proxy=1
# logging
log_level=info- helmet.js - sets various http headers for security
- rate limiting - prevents brute force attacks
- jwt - stateless authentication with secure tokens
- csrf protection - built-in csrf protection
- secure cookies - http-only and secure cookie options
- password hashing - uses hmac-sha256 with random salts
post /auth/register
content-type: application/json
{
"username": "user123",
"email": "[email protected]",
"password": "securepassword123"
}post /auth/login
content-type: application/json
{
"username": "user123",
"password": "securepassword123"
}get /auth/me
authorization: bearer <token>post /auth/logoutrun the test suite:
npm testnpm run lintnpm run formatnpm start- fork the repository
- create your feature branch (
git checkout -b feature/amazingfeature) - commit your changes (
git commit -m 'add some amazingfeature') - push to the branch (
git push origin feature/amazingfeature) - open a pull request
mit - see the license file for details.