@@ -2,6 +2,10 @@ import { NextFunction, Request, RequestHandler, Response } from 'express';
22import logger from '@/configs/logger.config' ;
33import { QRLoginTokenService } from "@/services/qr.service" ;
44import { QRLoginTokenResponseDto } from "@/types/dto/responses/qrResponse.type" ;
5+ import { InvalidTokenError , TokenExpiredError } from '@/exception/token.exception' ;
6+
7+ // TODO: randomUUID() 기반으로 길이 36
8+ type Token32 = string & { __lengthBrand : 32 } ;
59
610export class QRLoginController {
711 constructor ( private qrService : QRLoginTokenService ) { }
@@ -18,10 +22,12 @@ export class QRLoginController {
1822
1923 const token = await this . qrService . create ( user . id , ip , userAgent ) ;
2024
25+ const typedToken = token as Token32 ;
26+
2127 const response = new QRLoginTokenResponseDto (
2228 true ,
2329 'QR 토큰 생성 완료' ,
24- { token : token } ,
30+ { token : typedToken } ,
2531 null
2632 ) ;
2733 res . status ( 200 ) . json ( response ) ;
@@ -36,13 +42,13 @@ export class QRLoginController {
3642 const token = req . query . token as string ;
3743
3844 if ( ! token ) {
39- res . status ( 400 ) . json ( { success : false , message : '토큰이 필요합니다.' } ) ;
45+ throw new InvalidTokenError ( '토큰이 필요합니다.' ) ;
4046 }
4147
4248 const found = await this . qrService . getByToken ( token ) ;
4349
4450 if ( ! found ) {
45- res . status ( 404 ) . json ( { success : false , message : '유효하지 않거나 만료된 토큰입니다.' } ) ;
51+ throw new TokenExpiredError ( ) ;
4652 }
4753
4854 res . status ( 200 ) . json ( { success : true , message : '유효한 QR 토큰입니다.' , token : found } ) ;
@@ -51,4 +57,4 @@ export class QRLoginController {
5157 next ( error ) ;
5258 }
5359 } ;
54- }
60+ }
0 commit comments