Skip to content

Commit 8cd7818

Browse files
committed
refactor: auth 포함 websocket type 분리 #166
1 parent 1abdde9 commit 8cd7818

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

backend/src/battles/gateway/battles.gateway.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
import { Logger, OnModuleInit } from '@nestjs/common'
2-
import { Server, Socket } from 'socket.io'
3-
4-
interface SocketWithUserId extends Socket {
5-
data: {
6-
userId?: string
7-
}
8-
handshake: Socket['handshake'] & {
9-
auth: Socket['handshake']['auth'] & {
10-
userId?: string
11-
}
12-
}
13-
}
14-
2+
import { Server } from 'socket.io'
3+
import type { SocketWithUserId } from '../types/socket.types'
154
import {
165
WebSocketGateway,
176
SubscribeMessage,
@@ -68,7 +57,7 @@ export class BattlesGateway implements OnGatewayConnection, OnGatewayDisconnect,
6857

6958
try {
7059
const userId = client.handshake.auth.userId
71-
if (!userId || typeof userId !== 'string') {
60+
if (!userId) {
7261
throw new Error('userId가 필요합니다.')
7362
}
7463

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Socket } from 'socket.io'
2+
3+
export interface SocketWithUserId extends Socket {
4+
data: {
5+
userId?: string
6+
}
7+
handshake: Socket['handshake'] & {
8+
auth: Socket['handshake']['auth'] & {
9+
userId?: string
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)