https://github.com/mariatorrentedev/express-auth-api
Simple express auth service.
https://github.com/mariatorrentedev/express-auth-api
express node postgresql prisma-orm railway typescript
Last synced: 3 months ago
JSON representation
Simple express auth service.
- Host: GitHub
- URL: https://github.com/mariatorrentedev/express-auth-api
- Owner: mariatorrentedev
- Created: 2024-05-31T13:07:06.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-23T13:49:31.000Z (about 2 years ago)
- Last Synced: 2025-04-05T17:18:08.887Z (over 1 year ago)
- Topics: express, node, postgresql, prisma-orm, railway, typescript
- Language: TypeScript
- Homepage:
- Size: 82 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Express Auth API
Simple Authentication service using the following technologies:
- [Node](https://nodejs.org/en/)
- [Express](https://expressjs.com/en/api.html)
- [Prisma ORM](https://www.prisma.io/)
- [Railway](https://railway.app/)
## Table of Contents
- [API Overview](#api-overview)
- [Business Objects](#business-objects)
- [Run it locally](#run-it-locally)
- [Deploy it](#deploy-it)
## API Overview
```
/api
.
├── /auth
│ └── POST
│ ├── /login
| |__/signup
├── /users
│ └── GET
│ PUT
│ DELETE
│ └── /
```
### API Detail
| Method | Path | Purpose |
| :----------------- | :---------------------------------: | -------------------------------: |
| POST | /auth/login | Validates username & password |
| POST | /auth/signup | Register a user, generate token. |
| **PRIVATE ROUTES** | Only accessible for **ADMIN** role: |
| GET | /users | Get all users. |
| GET | /users/:id | Get user by id. |
| PUT | /users/:id | Update user by id. |
| DELETE | /users/:id | Delete user by id. |
---
## Business Objects
### Prisma Schema
- **Users (table)**
- id (auto-generated)
- email (string)
- password (string)
- role (enum)
- createdAt (Date)
- updatedAt (Date)
- authoredPosts (Array of blog posts)
## Run it locally
To build and run this app locally you will need a few things:
- Install [Git](https://www.git-scm.com/)
- Install [Node](https://nodejs.org/en/)
- Install [PostgreSQL](https://www.postgresql.org/download/) or any DB provider that you want to connect with prisma.
### Getting Started
- Clone the repository
```
git clone https://github.com/marialastNamedev/verse-bytes.git
```
_Note: wtfunk...my lastName word is confused in Railway as a missing dependency causing a deployment error, just copy the url above using the Code button._
- Create an `.env` file based on the example
```
mv example.env .env
```
- Install dependencies
```
npm install
```
- Run it
```
npm run dev
```
- Build it
```
npm run build
```
## Deploy it
### Railway
1. Go to your [Railway dashboard](https://railway.app/dashboard).
2. Create a new project and connect it to your current repository, deploy it.
3. Create another service insde the same project for the DB.
**_Note: This repo includes a GitHub workflow that will do CI/CD for both, the DB and the server. In order for it to work we would need to add some secrets to our repo:_**
4. Create a `RAILWAY_TOKEN` [here](https://railway.app/project/) under your project _settings>tokens_.
### Github
1. Go to your repository project settings.
2. Under _Security->Secrets and Variables>actions_ add 3 new repository secrets:
- `RAILWAY_TOKEN` create above.
- `RAILWAY_SERVICE_ID` cp value under _variables_ in Railway project dashboard.
- `DATABASE_URL` cp value under _variables_ from the DB service in Railway project dashboard.
3. This workflow will be triggered based on the `master` branch.