Skip to content

fioravante-dev/express-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ExpressAuth

RESTful API for authentication developed with Node.js, Express, Prisma, and Zod.
Follows a modular and secure architecture using access_token and refresh_token with JWT.

Repository: fioravante-dev/express-auth


βš™οΈ Technologies Used

  • Node.js + Express
  • TypeScript
  • Prisma ORM
  • Zod (schema validation)
  • JSON Web Token (JWT)
  • tsyringe (Dependency Injection)
  • Vitest
  • Docker

πŸš€ How to Run the Project Locally

# Install dependencies
npm install

# Configure the database
npx prisma migrate dev --name init

# Run the server
npm run dev

OR run the entire API using Docker:

docker-compose up

πŸ“¦ Environment Variables (.env)

Create a .env file at the root of the project with the following content:

DATABASE_URL=your-db-url
PORT=a-port # default 3333
JWT_ACCESS_SECRET=your-access-token-secret
JWT_REFRESH_SECRET=your-refresh-token-secret

πŸ” Authentication Endpoints

POST /register

Creates a new user.

Body:

{
  "email": "user@email.com",
  "password": "123456",
  "name": "Test User"
}

Response:

{
  "user": {
    "id": "...",
    "email": "...",
    "name": "...",
    "is_verified": false
  },
  "access_token": "...",
  "refresh_token": "..."
}

POST /login

Authenticates a user.

Body:

{
  "email": "user@email.com",
  "password": "123456"
}

Response:

{
  "user": {
    "id": "...",
    "email": "...",
    "name": "...",
    "is_verified": false
  },
  "access_token": "...",
  "refresh_token": "..."
}

POST /refresh

Generates a new pair of tokens from a valid refresh_token.

Body:

{
  "refresh_token": "..."
}

Response:

{
  "access_token": "...",
  "refresh_token": "..."
}

POST /logout

Revokes the refresh_token.

Body:

{
  "refresh_token": "..."
}

Response:

{
  "message": "Logged out successfully"
}

βœ… Future Improvements

  • Role-based authorization middleware (admin, user, etc.)
  • Swagger/OpenAPI documentation
  • More Automated tests with Jest or Vitest
  • OAuth
  • More routes

Made with dedication by Pedro Fioravante
Project: ExpressAuth

About

πŸ” ExpressAuth API Secure User Authentication

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published