diff --git a/src/middleware/authentication.ts b/src/middleware/authentication.ts index bcc5159..367bd1e 100644 --- a/src/middleware/authentication.ts +++ b/src/middleware/authentication.ts @@ -1,12 +1,13 @@ import { verify } from 'jsonwebtoken' import config from '#application/config' -import { gameLogger } from '#application/logger' +import Logger, { LoggerType } from '#application/logger' import { TSocket } from '#application/types' class SocketAuthenticator { private socket: TSocket private readonly next: any + private readonly logger = Logger.type(LoggerType.APP) constructor(socket: TSocket, next: any) { this.socket = socket @@ -15,14 +16,14 @@ class SocketAuthenticator { public async authenticate(): Promise { if (!this.socket.request.headers.cookie) { - gameLogger.warn('No cookie provided') + this.logger.warn('No cookie provided') return this.next(new Error('Authentication error')) } const token = this.parseCookies()['token'] if (!token) { - gameLogger.warn('No token provided') + this.logger.warn('No token provided') return this.next(new Error('Authentication error')) } @@ -40,7 +41,7 @@ class SocketAuthenticator { private verifyToken(token: string): void { verify(token, config.JWT_SECRET, (err: any, decoded: any) => { if (err) { - gameLogger.error('Invalid token') + this.logger.error('Invalid token') return this.next(new Error('Authentication error')) }