Skip to content

Commit 245a721

Browse files
committed
hotfix: token 36자가 아닌 10자로 수정
1 parent a95635e commit 245a721

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

src/controllers/qr.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { UserService } from '@/services/user.service';
77
import { NotFoundError } from '@/exception';
88
import { CookieOptions } from 'express';
99

10-
type Token32 = string & { __lengthBrand: 32 };
10+
type Token32 = string & { __lengthBrand: 10 };
1111

1212
export class QRLoginController {
1313
constructor(

src/services/__test__/qr.service.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ describe('QRLoginTokenService', () => {
2424
const userId = 1;
2525
const ip = '127.0.0.1';
2626
const userAgent = 'Chrome';
27-
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
28-
27+
2928
const token = await service.create(userId, ip, userAgent);
30-
31-
expect(token).toMatch(uuidRegex);
29+
30+
expect(typeof token).toBe('string');
31+
expect(token.length).toBe(10);
32+
expect(/^[A-Za-z0-9]{10}$/.test(token)).toBe(true);
3233
expect(repo.createQRLoginToken).toHaveBeenCalledWith(token, userId, ip, userAgent);
3334
});
3435

src/services/qr.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { QRLoginTokenRepository } from "@/repositories/qr.repository";
22
import { QRLoginToken } from "@/types/models/QRLoginToken.type";
3-
import { randomUUID } from "crypto";
3+
import { generateRandomToken } from '@/utils/generateRandomToken.util';
44

55
export class QRLoginTokenService {
66
constructor(private qrRepo: QRLoginTokenRepository) {}
77

88
async create(userId: number, ip: string, userAgent: string): Promise<string> {
9-
const token = randomUUID();
9+
const token = generateRandomToken(10);
1010
await this.qrRepo.createQRLoginToken(token, userId, ip, userAgent);
1111
return token;
1212
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { BaseResponseDto } from '@/types/dto/responses/baseResponse.type';
22

3-
type Token32 = string & { __lengthBrand: 32 };
3+
type Token10 = string & { __lengthBrand: 10 };
44

55
export interface QRLoginTokenResponseData {
6-
token: Token32;
6+
token: Token10;
77
}
88

99
export class QRLoginTokenResponseDto extends BaseResponseDto<QRLoginTokenResponseData> {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function generateRandomToken(length: number = 10): string {
2+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
3+
let result = '';
4+
for (let i = 0; i < length; i++) {
5+
result += chars.charAt(Math.floor(Math.random() * chars.length));
6+
}
7+
return result;
8+
}

0 commit comments

Comments
 (0)