https://github.com/sugiartofahmi/express-prisma-vercel
Learn to build an authentication REST API with prisma
https://github.com/sugiartofahmi/express-prisma-vercel
express jwt-authentication postgresql prisma vercel
Last synced: over 1 year ago
JSON representation
Learn to build an authentication REST API with prisma
- Host: GitHub
- URL: https://github.com/sugiartofahmi/express-prisma-vercel
- Owner: sugiartofahmi
- Created: 2023-06-24T15:51:26.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-14T01:45:06.000Z (almost 3 years ago)
- Last Synced: 2025-01-09T14:09:12.846Z (over 1 year ago)
- Topics: express, jwt-authentication, postgresql, prisma, vercel
- Language: JavaScript
- Homepage: https://express-prisma-jwt.vercel.app
- Size: 43 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Express Prisma JWT
Learn to create authentication with express js
## Installation
### Clone
```bash
git clone git@github.com:sugiartofahmi/express-refresh-token.git
```
### Install
```bash
yarn
```
### Development
```bash
yarn dev
```
## Setup
- ENV
1. rename .env-example to .env
2. change value on env
`PORT, DB_URL and JWT_SECRET`
example :
```bash
PORT = 9000
```
```bash
DB_URL = mongodb+srv://:@cluster0.8lcu8fs.mongodb.net/my-db
```
```bash
JWT_SECRET = jwtscrect
```
# API Spec
## Register
Endpoint : POST /auth/register
Request Body :
```json
{
"email": "test@gmail.com",
"password": "passwordmu",
"name": "Nama Kamu"
}
```
Response Body Success :
```json
{
"status": "success",
"user": {
"_id": "id",
"name": "Nama Kamu",
"email": "test@gmail.com"
}
}
```
Response Body Error :
```json
{
"status": "failed",
"message": "email already exist, please login"
}
```
```json
{
"status": "failed",
"message": "password not match"
}
```
## Login
Endpoint : POST /auth/login
Request Body :
```json
{
"email": "test@gmail.com",
"password": "passwordmu"
}
```
Response Body Success :
```json
{
"status": "success",
"user": {
"_id": "id",
"name": "Nama Kamu",
"email": "test@gmail.com"
},
"token": {
"access_token": "unique-token",
"refresh_token": "unique-token"
}
}
```
Response Body Error :
```json
{
"status": "failed",
"message": "account not found"
}
```
```json
{
"status": "failed",
"message": "Wrong password"
}
```
## Refresh Token
Endpoint : POST /auth/refresh
Request Body :
```json
{
"refresh_token": "unique-token"
}
```
Response Body Success :
```json
{
"status": "success",
"access_token": "unique-token"
}
```
Response Body Error :
```json
{
"status": "failed",
"message": "Token is not valid"
}
```
## Get User
Endpoint : GET /user/me
Headers :
- Authorization :Bearer token
Response Body Success:
```json
{
"status": "success",
"user": {
"_id": "id",
"name": "Nama Kamu",
"email": "test@gmail.com"
}
}
```
Response Body Error :
```json
{
"status": "failed",
"message": "Token is not valid"
}
```
## Logout
Endpoint : POST /auth/logout
Request Body :
```json
{
"refresh_token": "unique-token"
}
```
Response Body Success:
```json
{
"status": "success",
"message": "Logged Out Sucessfully"
}
```
Response Body Error :
```json
{
"status": "failed",
"message": "Invalid token"
}
```