Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ curl -X 'POST' \
Email verification may also be required.
:::

List of possible errors:
| Error | Condition |
| ------------------------------------- | ---------------------------------------------------------------- |
| `"errors.firstname_should_be_string"` | When firstName is not a string |
| `"errors.firstname_too_short"` | When firstName is < 2 characters |
| `"errors.firstname_too_long"` | When firstName is > 20 characters |
| `"errors.lastname_should_be_string"` | When lastName is not a string |
| `"errors.lastname_too_short"` | When lastName is < 2 characters |
| `"errors.lastname_too_long"` | When lastName is > 20 characters |
| `"errors.invalid_age"` | When age is either not a number or is negative |
| `"errors.invalid_email"` | When email is invalid |
| `"errors.invalid_password"` | When password is not a string |
| `"errors.password_too_short"` | When password is < 8 characters |
| `"errors.password_too_long"` | When password is > 30 characters |
| `"errors.invalid_address"` | When address is not a string |
| `"errors.invalid_phone_number"` | When phone number is invalid (needs + and country code) |
| `"errors.invalid_zipcode"` | When zipcode is not a string |
| `"errors.invalid_avatar"` | When avatar url is not a url |
| `"errors.invalid_gender"` | When gender is not `'MALE'`, `'FEMALE'` or `'OTHER'` |
| `"errors.email_in_use"` | When email is already registered |


## Sign In

- Method: `POST`
Expand Down Expand Up @@ -120,6 +142,15 @@ curl -X 'POST' \
}
```

List of possible errors:
| Error | Condition |
| ------------------------------------- | ---------------------------------------------------------------- |
| `"errors.incorrect_email_or_password"`| When the email or password is incorrect |
| `"errors.invalid_email"` | When the email is invalid |
| `"errors.should_provide_email"` | When the email is not sent with the request body |
| `"errors.invalid_email"` | When the password is not sent with the request body |


## Verify Email

- Method: `POST`
Expand Down Expand Up @@ -154,6 +185,12 @@ curl -X 'POST' \
The user will be required to follow the verification link sent to their email.
:::

List of possible errors:
| Error | Condition |
| ------------------------------------- | ---------------------------------------------------------------- |
| `"errors.invalid_email"` | When the email is invalid |
| `"errors.already_verified"` | When the email has already been verified |

## Get Current User

- Method: `GET`
Expand Down Expand Up @@ -210,6 +247,10 @@ curl -X 'GET' \
-H 'accept: application/json'
```

::: info NOTE
requires access token attatched either to cookies or `Authorization` header.
:::

### Response

```json
Expand All @@ -231,6 +272,12 @@ curl -X 'GET' \
}
```

List of possible errors:
| Error | Condition |
| ------------------------------------- | ---------------------------------------------------------------- |
| `"errors.user_not_found"` | When a user could not be found with the given id |


## Get All Users

- Method: `GET`
Expand All @@ -249,6 +296,10 @@ curl -X 'GET' \
-H 'accept: */*'
```

::: info NOTE
requires access token attatched either to cookies or `Authorization` header.
:::

### Response

```json
Expand Down Expand Up @@ -321,6 +372,12 @@ Response body
Server must get someway refresh_token, it could be from body, cookie or header.
:::

List of possible errors:
| Error | Condition |
| ------------------------------------- | ---------------------------------------------------------------- |
| `"errors.token_not_found"` | When there is no refresh token in the body, cookie or header |


## Update User Data

- Method: `PATCH`
Expand Down Expand Up @@ -380,6 +437,8 @@ curl -X 'PATCH' \
}
```

List of possible errors: Same as Sign Up

## Recover Password

- METHOD: `POST`
Expand Down Expand Up @@ -415,6 +474,11 @@ This changes user's password into an automatically generated one which will be s
The user then can access his account with it and optionally [change it](#change-password).
:::

List of possible errors:
| Error | Condition |
| ------------------------------------- | ---------------------------------------------------------------- |
| `"errors.invalid_email"` | When the email is invalid |

## Change Password

- Method: `PATCH`
Expand Down Expand Up @@ -456,6 +520,16 @@ curl -X 'PATCH' \
This endpoint essentialy signs the user in again, hence the tokens in response.
:::

List of possible errors:
| Error | Condition |
| ------------------------------------- | ---------------------------------------------------------------- |
| `"errors.invalid_old_password"` | When the old password is not a string |
| `"errors.old_password_incorrect"` | When the old password is incorrect |
| `"errors.invalid_change_password"` | When the new password is not a string |
| `"errors.new_password_matches_old"` | When the new password is the same as the old one |
| `"errors.password_too_short"` | When the new password is shorter than 8 characters |
| `"errors.password_too_long"` | When the new password is longer than 30 characters |

## Interface of JWT Token

This [content](https://github.com/educata/everrest/blob/main/src/interfaces/user.interface.ts#L24) will be encoded inside the JWT token.
Expand Down
2 changes: 1 addition & 1 deletion docs/product.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ curl -X 'GET' \
- `rating`: number
- `price_min`: number
- `price_max`: number
- `sort_by`: `"rating"`, `"price"`, `"isse_date"`, `"title"`
- `sort_by`: `"rating"`, `"price"`, `"issue_date"`, `"title"`
- `sort_direction`: `"asc"`, `"desc"`

::: info NOTE
Expand Down
2 changes: 1 addition & 1 deletion src/modules/user/auth/guards/local-auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class LocalAuthGuard extends AuthGuard('local') {
if (!email && !password) {
this.exceptionService.throwError(
ExceptionStatusKeys.BadRequest,
'Should be provide: Email and Password',
'Should be provided: Email and Password',
[
AuthExpectionKeys.ShouldProvideEmail,
AuthExpectionKeys.ShouldProvidePassword,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/user/dtos/sign-up.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class SignUpDto {
message: AuthExpectionKeys.FirstnameTooShort,
})
@MaxLength(API_CONFIG.MAX_FIRSTNAME_LENGTH, {
message: AuthExpectionKeys.LastnameTooLong,
message: AuthExpectionKeys.FirstnameTooLong,
})
firstName: string;

Expand Down