AnhLedger commited on
Commit
690d7c7
1 Parent(s): 8283e17

return user object when getProfile

Browse files
backend/src/modules/authentication/authentication.controller.ts CHANGED
@@ -33,6 +33,7 @@ export class AuthenticationController {
33
  // @UseGuards(AuthenticationGuard)
34
  @Get('profile')
35
  getProfile(@Request() req) {
36
- return req.user;
 
37
  }
38
  }
 
33
  // @UseGuards(AuthenticationGuard)
34
  @Get('profile')
35
  getProfile(@Request() req) {
36
+ const userId = req.user.sub;
37
+ return this.AuthenticationService.getProfile(userId);
38
  }
39
  }
backend/src/modules/authentication/authentication.service.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { ConflictException, Injectable, UnauthorizedException } from '@nestjs/common';
2
  import { UserService } from '../user/user.service.js';
3
  import * as bcrypt from 'bcrypt';
4
  import { JwtService } from '@nestjs/jwt';
5
  import { SignUpDto } from './dto/sign-up.dto.js';
6
- import { UserEntity } from 'src/entities/user.entity.js';
7
  @Injectable()
8
  export class AuthenticationService {
9
  constructor(
@@ -70,4 +70,12 @@ export class AuthenticationService {
70
  throw new ConflictException(fieldName + ' is already taken');
71
  }
72
  }
 
 
 
 
 
 
 
 
73
  }
 
1
+ import { ConflictException, Get, Injectable, UnauthorizedException } from '@nestjs/common';
2
  import { UserService } from '../user/user.service.js';
3
  import * as bcrypt from 'bcrypt';
4
  import { JwtService } from '@nestjs/jwt';
5
  import { SignUpDto } from './dto/sign-up.dto.js';
6
+ import { UserEntity } from '../../entities/user.entity.js';
7
  @Injectable()
8
  export class AuthenticationService {
9
  constructor(
 
70
  throw new ConflictException(fieldName + ' is already taken');
71
  }
72
  }
73
+
74
+ async getProfile(userId: string) {
75
+ const user = await UserEntity.findOne({
76
+ where: { id: userId }
77
+ });
78
+ const { hash_password, ...userWithoutHash } = user;
79
+ return userWithoutHash;
80
+ }
81
  }