Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 17 days 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 (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-14T01:45:06.000Z (over 1 year ago)
- Last Synced: 2023-07-14T02:33:08.984Z (over 1 year ago)
- Topics: express, jwt-authentication, postgresql, prisma, vercel
- Language: JavaScript
- Homepage: https://express-prisma-jwt.vercel.app
- Size: 41 KB
- Stars: 1
- 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 [email protected]: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": "[email protected]",
"password": "passwordmu",
"name": "Nama Kamu"
}
```Response Body Success :
```json
{
"status": "success",
"user": {
"_id": "id",
"name": "Nama Kamu",
"email": "[email protected]"
}
}
```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": "[email protected]",
"password": "passwordmu"
}
```Response Body Success :
```json
{
"status": "success",
"user": {
"_id": "id",
"name": "Nama Kamu",
"email": "[email protected]"
},
"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": "[email protected]"
}
}
```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"
}
```