From cda7719479b7bdd5588d2fc9c06bb25b31d7f54e Mon Sep 17 00:00:00 2001 From: silacs Date: Wed, 5 Feb 2025 23:47:45 +0400 Subject: [PATCH 1/4] Added list of errors on sign up request in the docs --- docs/authentication.md | 21 +++++++++++++++++++++ src/modules/user/dtos/sign-up.dto.ts | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/authentication.md b/docs/authentication.md index a7f5546..f4b272a 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -88,6 +88,27 @@ curl -X 'POST' \ Email verification may also be required. ::: +::: info NOTE +List of possible errors: +`"errors.firstname_should_be_string"` when first name is not a string +`"errors.firstname_too_short"` when first name length is < 2 characters +`"errors.firstname_too_long"` when first name length is > 20 characters +`"errors.lastname_should_be_string"` when last name is not a string +`"errors.lastname_too_short"` when last name is < 2 characters +`"errors.lastname_too_long"` when last name 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 to have country code with +) +`"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 in use +::: + ## Sign In - Method: `POST` diff --git a/src/modules/user/dtos/sign-up.dto.ts b/src/modules/user/dtos/sign-up.dto.ts index c89f305..b490fc3 100644 --- a/src/modules/user/dtos/sign-up.dto.ts +++ b/src/modules/user/dtos/sign-up.dto.ts @@ -20,7 +20,7 @@ export class SignUpDto { message: AuthExpectionKeys.FirstnameTooShort, }) @MaxLength(API_CONFIG.MAX_FIRSTNAME_LENGTH, { - message: AuthExpectionKeys.LastnameTooLong, + message: AuthExpectionKeys.FirstnameTooLong, }) firstName: string; From d945ce18f13b2b36c6da7a10c20c60baad61d853 Mon Sep 17 00:00:00 2001 From: silacs Date: Thu, 6 Feb 2025 14:42:01 +0400 Subject: [PATCH 2/4] changed the signup errors into a table, made minor changes to the descriptions --- docs/authentication.md | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/docs/authentication.md b/docs/authentication.md index f4b272a..ef3268e 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -90,23 +90,26 @@ Email verification may also be required. ::: info NOTE List of possible errors: -`"errors.firstname_should_be_string"` when first name is not a string -`"errors.firstname_too_short"` when first name length is < 2 characters -`"errors.firstname_too_long"` when first name length is > 20 characters -`"errors.lastname_should_be_string"` when last name is not a string -`"errors.lastname_too_short"` when last name is < 2 characters -`"errors.lastname_too_long"` when last name 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 to have country code with +) -`"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 in use +| 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 From c598444b410f6c2695bf2538a2a7bb2f4e1cc5ec Mon Sep 17 00:00:00 2001 From: silacs Date: Thu, 6 Feb 2025 22:57:16 +0400 Subject: [PATCH 3/4] fixed typo on product documentation --- docs/product.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/product.md b/docs/product.md index b9cb2f4..aee897d 100644 --- a/docs/product.md +++ b/docs/product.md @@ -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 From 0fca2a717a6fcc9621ee071686e176de25290fab Mon Sep 17 00:00:00 2001 From: silacs Date: Mon, 28 Jul 2025 18:46:17 +0400 Subject: [PATCH 4/4] Finished error documentation on auth endpoints --- docs/authentication.md | 56 ++++++++++++++++++- .../user/auth/guards/local-auth.guard.ts | 2 +- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/docs/authentication.md b/docs/authentication.md index ef3268e..77fc050 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -88,7 +88,6 @@ curl -X 'POST' \ Email verification may also be required. ::: -::: info NOTE List of possible errors: | Error | Condition | | ------------------------------------- | ---------------------------------------------------------------- | @@ -109,8 +108,7 @@ List of possible errors: | `"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 @@ -144,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` @@ -178,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` @@ -234,6 +247,10 @@ curl -X 'GET' \ -H 'accept: application/json' ``` +::: info NOTE +requires access token attatched either to cookies or `Authorization` header. +::: + ### Response ```json @@ -255,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` @@ -273,6 +296,10 @@ curl -X 'GET' \ -H 'accept: */*' ``` +::: info NOTE +requires access token attatched either to cookies or `Authorization` header. +::: + ### Response ```json @@ -345,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` @@ -404,6 +437,8 @@ curl -X 'PATCH' \ } ``` +List of possible errors: Same as Sign Up + ## Recover Password - METHOD: `POST` @@ -439,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` @@ -480,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. diff --git a/src/modules/user/auth/guards/local-auth.guard.ts b/src/modules/user/auth/guards/local-auth.guard.ts index 0bb5e3b..9fb3f23 100644 --- a/src/modules/user/auth/guards/local-auth.guard.ts +++ b/src/modules/user/auth/guards/local-auth.guard.ts @@ -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,