Skip to content

Commit

Permalink
Return 500 when no user in session
Browse files Browse the repository at this point in the history
  • Loading branch information
codicocodes committed Feb 5, 2024
1 parent 2a4ae78 commit 053c2d4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/back-nest/src/users/controllers/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Controller, Get, Req } from '@nestjs/common';
import { Controller, Get, HttpException, Req } from '@nestjs/common';
import { Request } from 'express';
import { User } from '../entities/user.entity';

@Controller('user')
export class UserController {
@Get()
getCurrentUser(@Req() request: Request): User {
return request.session?.user;
if (!request.session?.user) {
throw new HttpException('Internal server error', 500);
}
return request.session.user;
}
}

0 comments on commit 053c2d4

Please sign in to comment.