An open API service indexing awesome lists of open source software.

https://github.com/heathlogancampbell/restful-login

🚪A simple restful login system, jwt, sequelize, express, passport
https://github.com/heathlogancampbell/restful-login

jwt mysql passport rest sequelize website

Last synced: about 1 month ago
JSON representation

🚪A simple restful login system, jwt, sequelize, express, passport

Awesome Lists containing this project

README

          

# REST Login system
A REST login system.
as time goes on, we are getting introducted to new technology everyday, so it's getting a bit out of hand,
so we need modular code.

## How it works
1. a user registers with their email and password
2. the password is encrypted and stored in a database
3. you then signin with your username and password which will return you with a JWT
4. you now make requests with your header being the JWT

## Calls
### Sign up
```
POST /api/user/signup

Body (json)
{
"email": "Akl@gmail.com",
"password": "asdas"
}
```
Create an account,
if there is any problems such as missing field, email incorrect format, you'll recieve a meaningful error

**Successful output**
```json
{
"message": "successfully created new user",
"version": "yeet"
}
```

Click for HTTP Request

```http
POST /api/user/signup HTTP/1.1
Host: localhost:3000
Content-Type: application/json
cache-control: no-cache

{
"email": "Akl@gmail.com",
"password": "asdas"
}
```

### Sign in
```
POST /api/user/signin

Body (json)
{
"email": "Akl@gmail.com",
"password": "asdas"
}
```
Get your jwt token from the server

**Successful output**
```json
{
"success": true,
"token": "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFAZ21haWwuY29tIiwiaWF0IjoxNTc1Mzc4MzUyLCJleHAiOjE1NzUzOTYzNTJ9.OMi6iXhdqdFI0iFKJSyx0hLJPhnXTUVI6VW7l_C3n20"
}
```

Click for HTTP Request

```http
POST /api/user/signin HTTP/1.1
Host: localhost:3000
Content-Type: application/json
cache-control: no-cache

{
"email": "Akl@gmail.com",
"password": "asdas"
}
```

### Can Access
```
GET /api/user/can-access
```

will return something if you're autherizied

**Successful output**
```json
{
"Animal": "Dogs"
}
```

Click for HTTP Request

```http
GET /api/user/can-access HTTP/1.1
Host: localhost:3000
Authorization: JWT
cache-control: no-cache

```

## Tools
- MySql (database)
- jwt (Json web tokens)
- sequelize (MySql ORM)
- express (http management tool)
- passport (Passport is authentication middleware)

## What I would do differently next time
* I would first formilize the return stucture of payloads, so it's less messy
* I would use another more structured language like java or C# (Maybe even typescript)