-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): fixing i18n translations at strategies and guards
- Loading branch information
1 parent
35bd004
commit 2f74295
Showing
10 changed files
with
98 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,59 @@ | ||
/* DO NOT EDIT, file generated by nestjs-i18n */ | ||
|
||
import { Path } from "nestjs-i18n"; | ||
import { Path } from 'nestjs-i18n'; | ||
export type I18nTranslations = { | ||
"auth": { | ||
"errors": { | ||
"user-not-found": string; | ||
"incorrect-password": string; | ||
}; | ||
"validations": { | ||
"EMAIL_IS_DEFINED": string; | ||
"EMAIL_IS_EMAIL": string; | ||
"PASSWORD_IS_DEFINED": string; | ||
"PASSWORD_IS_STRING": string; | ||
}; | ||
auth: { | ||
validations: { | ||
EMAIL_IS_DEFINED: string; | ||
EMAIL_IS_EMAIL: string; | ||
PASSWORD_IS_DEFINED: string; | ||
PASSWORD_IS_STRING: string; | ||
}; | ||
"course": { | ||
"validations": { | ||
"TITLE_IS_DEFINED": string; | ||
"TITLE_IS_STRING": string; | ||
"TITLE_IS_NOT_EMPTY": string; | ||
"DESCRIPTION_IS_DEFINED": string; | ||
"DESCRIPTION_IS_STRING": string; | ||
"DESCRIPTION_IS_NOT_EMPTY": string; | ||
"PRICE_IS_DEFINED": string; | ||
"PRICE_IS_NUMBER": string; | ||
"PRICE_MIN": string; | ||
"INSTRUCTOR_IS_DEFINED": string; | ||
"INSTRUCTOR_IS_UUID": string; | ||
"STUDENT_IS_DEFINED": string; | ||
"STUDENT_IS_UUID": string; | ||
}; | ||
"errors": { | ||
"invalid-money": string; | ||
"instructor-not-found": string; | ||
"course-not-found": string; | ||
"student-not-found": string; | ||
"student-already-enrolled": string; | ||
}; | ||
errors: { | ||
'user-not-found': string; | ||
'incorrect-password': string; | ||
'no-authorization': string; | ||
}; | ||
"user": { | ||
"validations": { | ||
"EMAIL_IS_EMAIL": string; | ||
"NAME_IS_DEFINED": string; | ||
"NAME_IS_STRING": string; | ||
"NAME_IS_NOT_EMPTY": string; | ||
"PASSWORD_IS_DEFINED": string; | ||
"PASSWORD_IS_STRING": string; | ||
"PASSWORD_IS_NOT_EMPTY": string; | ||
}; | ||
"errors": { | ||
"duplicated-email": string; | ||
"invalid-email": string; | ||
"invalid-name": string; | ||
}; | ||
}; | ||
course: { | ||
validations: { | ||
TITLE_IS_DEFINED: string; | ||
TITLE_IS_STRING: string; | ||
TITLE_IS_NOT_EMPTY: string; | ||
DESCRIPTION_IS_DEFINED: string; | ||
DESCRIPTION_IS_STRING: string; | ||
DESCRIPTION_IS_NOT_EMPTY: string; | ||
PRICE_IS_DEFINED: string; | ||
PRICE_IS_NUMBER: string; | ||
PRICE_MIN: string; | ||
INSTRUCTOR_IS_DEFINED: string; | ||
INSTRUCTOR_IS_UUID: string; | ||
STUDENT_IS_DEFINED: string; | ||
STUDENT_IS_UUID: string; | ||
}; | ||
errors: { | ||
'invalid-money': string; | ||
'instructor-not-found': string; | ||
'course-not-found': string; | ||
'student-not-found': string; | ||
'student-already-enrolled': string; | ||
}; | ||
}; | ||
user: { | ||
validations: { | ||
EMAIL_IS_EMAIL: string; | ||
NAME_IS_DEFINED: string; | ||
NAME_IS_STRING: string; | ||
NAME_IS_NOT_EMPTY: string; | ||
PASSWORD_IS_DEFINED: string; | ||
PASSWORD_IS_STRING: string; | ||
PASSWORD_IS_NOT_EMPTY: string; | ||
}; | ||
errors: { | ||
'duplicated-email': string; | ||
'invalid-email': string; | ||
'invalid-name': string; | ||
}; | ||
}; | ||
}; | ||
export type I18nPath = Path<I18nTranslations>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
{ | ||
"errors": { | ||
"user-not-found": "Could not find a user with the provided e-mail.", | ||
"incorrect-password": "The provided password is incorrect." | ||
}, | ||
"validations": { | ||
"EMAIL_IS_DEFINED": "You need to send the e-mail to authenticate.", | ||
"EMAIL_IS_EMAIL": "You need to send a valid e-mail to authenticate.", | ||
"PASSWORD_IS_DEFINED": "You need to send your password to authenticate.", | ||
"PASSWORD_IS_STRING": "You need to send a valid password to authenticate." | ||
}, | ||
"errors": { | ||
"user-not-found": "Could not find a user with the provided e-mail.", | ||
"incorrect-password": "The provided password is incorrect.", | ||
"no-authorization": "You are not authorized to access this resource." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
{ | ||
"errors": { | ||
"user-not-found": "Não foi possível encontrar um usuário com o e-mail enviado.", | ||
"incorrect-password": "Senha incorreta." | ||
}, | ||
"validations": { | ||
"EMAIL_IS_DEFINED": "É necessário enviar o e-mail para realizar a autenticação.", | ||
"EMAIL_IS_EMAIL": "É necessário enviar um e-mail válido.", | ||
"PASSWORD_IS_DEFINED": "É necessário enviar a senha para realizar a autenticação.", | ||
"PASSWORD_IS_STRING": "É necessário enviar uma senha válida." | ||
}, | ||
"errors": { | ||
"user-not-found": "Não foi possível encontrar um usuário com o e-mail enviado.", | ||
"incorrect-password": "Senha incorreta.", | ||
"no-authorization": "Você não é autorizado para acessar este recurso." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ | |
"invalid-email": "O e-mail enviado está inválido.", | ||
"invalid-name": "O nome enviado está inválido." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { RequestUserEntity } from '@modules/auth/domain/entities/request-user.entity'; | ||
import { Injectable, UnauthorizedException } from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { I18nContext } from 'nestjs-i18n'; | ||
import { I18nTranslations } from 'src/generated/i18n.generated'; | ||
|
||
@Injectable() | ||
export class AuthJwtGuard extends AuthGuard('jwt') {} | ||
export class AuthJwtGuard extends AuthGuard('jwt') { | ||
handleRequest<T = RequestUserEntity>(err: Error, user: T | false): T { | ||
const i18n = I18nContext.current<I18nTranslations>(); | ||
|
||
if (err || !user) { | ||
throw ( | ||
err || | ||
new UnauthorizedException(i18n?.t('auth.errors.no-authorization')) | ||
); | ||
} | ||
|
||
return user; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters