Newer
Older
```
/auth/login
```
Request format:
```json
{
"email": "joebloggs@gmail.com",
"password": "password123"
}
```
Responses:
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#### 200 - Success
If the authentication was successful - meaning the email address provided matched a password for that account.
This generates a JSON Web Token (JWT) that will be returned to the user in the response body below.
Example:
```json
{
"token": "lppo32fiw4jfiweniseyuw4rfjes38died8ejwfuiwhh383dfho"
}
```
#### 500 - Internal Server Error
If there was an exception thrown or an error on the server side whilst processing the login request this 500 response
will be returned to the caller in the following format.
Example:
```json
{
"message": "Internal server error",
"error": "Unable to parse JSON request"
}
```
#### 400 - Incorrect body
If the request body is not in the correct format or the validation for the required fields failed then a response with a status code of 400 will be returned.
Example:
```json
{
"message": "The 'email' field is required and was not provided."
}
```
#### 401 - Unauthorized
If the email and password provided did not match then a 401 response will be returned.
```json
{
"message": "Invalid credentials"
}
```
## Register
```
/auth/register
```
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#### 200 - Success
If the registration was successful - meaning the details provided to the endpoint were used to create an account.
This generates a JSON Web Token (JWT) that will be returned to the user in the response body below.
Example:
```json
{
"token": "lppo32fiw4jfiweniseyuw4rfjes38died8ejwfuiwhh383dfho"
}
```
#### 500 - Internal Server Error
If there was an exception thrown or an error on the server side whilst processing the registration request this 500 response
will be returned to the caller in the following format.
Example:
```json
{
"message": "Internal server error",
"error": "Unable to parse JSON request"
}
```
#### 400 - Incorrect body
If the request body is not in the correct format or the validation for the required fields failed then a response with a status code of 400 will be returned.
Example:
```json
{
"message": "The 'email' field is required and was not provided."
}
```
## JWT Validation
### Information
JWT validation:
```
Algorithm: HS512
```
### Step by step
Add the following library to the project.
```
npm add jwt-simple
```
Consume the JWT secret to decode the application and pas it into the decode function provided by the library.
```
```