-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: redis exists 메서드 생성 * refactor: show quiz 책임 분리 * feat: 클래스가 비어있을 경우 빈 배열 반환 * feat: 퀴즈 다음 순서로 이동할 수 있게 추가 * feat: get class 오름차순 정렬 반환 * feat: 게임 상태 랭킹, 리더보드 추가 * feat: 실시간 소켓 서버 sid 가드 구현 * feat: 게이트웨이 가드 설정 --------- Co-authored-by: nowChae <[email protected]>
- Loading branch information
Showing
6 changed files
with
64 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common'; | ||
import { Observable } from 'rxjs'; | ||
import { RedisService } from '../../config/database/redis/redis.service'; | ||
import { WsException } from '@nestjs/websockets'; | ||
|
||
@Injectable() | ||
export class SessionGuard implements CanActivate { | ||
constructor(private redisService: RedisService) {} | ||
|
||
async canActivate(context: ExecutionContext) { | ||
const client = context.switchToWs().getClient(); | ||
|
||
const { sid } = client.handshake.auth; | ||
|
||
if (!sid) { | ||
client.emit('error', { message: 'Session ID not exists in Cookie.' }); | ||
return false; | ||
} | ||
|
||
if ( | ||
(await this.redisService.exists(`master_sid=${sid}`)) || | ||
(await this.redisService.exists(`participant_sid=${sid}`)) | ||
) { | ||
client.emit('error', { message: 'Session ID not exists in Redis.' }); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters