File tree Expand file tree Collapse file tree 4 files changed +10
-22
lines changed
Expand file tree Collapse file tree 4 files changed +10
-22
lines changed Original file line number Diff line number Diff line change @@ -12,12 +12,13 @@ export class AuthService {
1212 this . redis = this . redisService . getOrThrow ( ) ;
1313 }
1414
15- async getUserIdFromSession ( sid : string ) : Promise < number | null > {
15+ async getUserIdFromSession ( sid : string ) : Promise < [ number , string ] | null > {
1616 const session = JSON . parse ( await this . redis . get ( `user:${ sid } ` ) ) ;
1717 if ( ! session ) return null ;
1818 const userId = session . id ;
19- if ( ! userId ) return null ;
20- return userId ;
19+ const userLoginId = session . loginId ;
20+ if ( ! userId || ! userLoginId ) return null ;
21+ return [ userId , userLoginId ] ;
2122 }
2223
2324 async setUserStatusLogin ( sid : string ) {
Original file line number Diff line number Diff line change @@ -34,10 +34,6 @@ export class UserService {
3434 this . redis = this . redisService . getOrThrow ( ) ;
3535 }
3636
37- async getUser ( userId : number ) {
38- return await this . userRepository . findById ( userId ) ;
39- }
40-
4137 async registerUser ( userCreateDto : UserCreateDto , role : string = USER_ROLE . USER ) {
4238 if ( await this . userRepository . findByLoginId ( userCreateDto . loginId ) ) {
4339 throw new ConflictException ( '이미 존재하는 사용자입니다.' ) ;
Original file line number Diff line number Diff line change 11import { Injectable } from '@nestjs/common' ;
22
33import { AuthService } from 'src/auth/service/auth.service' ;
4- import { User } from 'src/domains/user/entity/user.entity' ;
5- import { UserService } from 'src/domains/user/service/user.service' ;
64
75import { UserParamDto } from './userParamDto' ;
86
97@Injectable ( )
108export class UserDecoratorService {
11- constructor (
12- private readonly userService : UserService ,
13- private readonly authService : AuthService ,
14- ) { }
9+ constructor ( private readonly authService : AuthService ) { }
1510
1611 async getUserParam ( ctx : any ) {
1712 const req = ctx . switchToHttp ( ) . getRequest ( ) ;
1813 const sid = req . cookies [ 'SID' ] ;
19- const userId = await this . authService . getUserIdFromSession ( sid ) ;
20-
21- if ( ! userId ) return null ;
22-
23- const user : User = await this . userService . getUser ( userId ) ;
24- return new UserParamDto ( user ) ;
14+ if ( ! sid ) return ;
15+ const [ userId , userLoginId ] = await this . authService . getUserIdFromSession ( sid ) ;
16+ if ( ! userId || ! userLoginId ) return null ;
17+ return new UserParamDto ( { id : userId , loginId : userLoginId } ) ;
2518 }
2619}
Original file line number Diff line number Diff line change 11export class UserParamDto {
2- constructor ( { id, loginId, loginPassword } ) {
2+ constructor ( { id, loginId } ) {
33 this . id = id ;
44 this . loginId = loginId ;
5- this . loginPassword = loginPassword ;
65 }
76
87 id : number ;
98 loginId : string ;
10- loginPassword : string ;
119}
You can’t perform that action at this time.
0 commit comments