Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add authentification with jwt and protected all route apart rou… #60

Merged
merged 7 commits into from
Oct 19, 2024
188 changes: 185 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.0.0",
"@nestjs/jwt": "^10.2.0",
"@nestjs/mongoose": "^10.0.10",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"bcrypt": "^5.1.1",
"bcryptjs": "^2.4.3",
"mongoose": "^8.7.0",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
},
Expand Down
4 changes: 3 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import { PermissionModule } from './modules/permission/permission.module';
import { PosModule } from './modules/pos/pos.module';
import { RestaurantsModule } from './modules/restaurants/restaurants.module';
import { UsersModule } from './modules/users/users.module';
import { PassportModule } from '@nestjs/passport';

@Module({
imports: [
PassportModule.register({ defaultStrategy : 'jwt' }), /**< Register new configuration authentification */
ConfigModule.forRoot(), /**< Loads environment configuration */
DetailsModule, /**< Manages restaurant details */
FoodModule, /**< Handles food-related functionality */
Expand All @@ -33,7 +35,7 @@ import { UsersModule } from './modules/users/users.module';
PermissionModule, /**< Manages permissions in the system */
PosModule, /**< Handles point-of-sale functionality */
RestaurantsModule, /**< Manages restaurant information */
UsersModule, /**< Manages users and their information */
UsersModule, /**< Manages users and their information */
],
controllers: [AppController], /**< Application controller */
providers: [AppService], /**< Core application service */
Expand Down
7 changes: 7 additions & 0 deletions src/modules/details/details.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import {
Delete,
NotFoundException,
BadRequestException,
UseGuards,
HttpException,
HttpStatus,
} from '@nestjs/common';
import { DetailsService } from './details.service';
import { JwtAuthGuard } from 'src/shared/guards/jwt-auth.guard';

@Controller('api/:idRestaurant/details')
export class DetailsController {
Expand All @@ -35,6 +37,7 @@ export class DetailsController {
* @throws {HttpException} - Throws if there is an error during retrieval.
* @async
*/
@UseGuards(JwtAuthGuard)
@Get()
async getAllDetail(@Param('idRestaurant') idRestaurant: number) {
try {
Expand All @@ -61,6 +64,7 @@ export class DetailsController {
* @throws {HttpException} - Throws if there is an error during retrieval.
* @async
*/
@UseGuards(JwtAuthGuard)
@Get(':id')
async getOneDetail(
@Param('idRestaurant') idRestaurant: number,
Expand Down Expand Up @@ -93,6 +97,7 @@ export class DetailsController {
* @throws {HttpException} - Throws if there is an error during creation.
* @async
*/
@UseGuards(JwtAuthGuard)
@Post()
async createDetail(
@Param('idRestaurant') idRestaurant: number,
Expand Down Expand Up @@ -130,6 +135,7 @@ export class DetailsController {
* @throws {HttpException} - Throws if there is an error during the update.
* @async
*/
@UseGuards(JwtAuthGuard)
@Put(':id')
async updateOneDetail(
@Param('idRestaurant') idRestaurant: number,
Expand Down Expand Up @@ -167,6 +173,7 @@ export class DetailsController {
* @throws {HttpException} - Throws if there is an error during deletion.
* @async
*/
@UseGuards(JwtAuthGuard)
@Delete(':id')
async deleteOneDetail(
@Param('idRestaurant') idRestaurant: number,
Expand Down
Loading
Loading