Renamed folder
This commit is contained in:
22
src/events/login.ts
Normal file
22
src/events/login.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import UserRepository from '#repositories/userRepository'
|
||||
|
||||
export default class LoginEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('login', this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private handleEvent(): void {
|
||||
try {
|
||||
if (!this.socket.userId) {
|
||||
this.logger.warn('Login attempt without user data')
|
||||
return
|
||||
}
|
||||
|
||||
this.socket.emit('logged_in', { user: UserRepository.getById(this.socket.userId) })
|
||||
this.logger.info(`User logged in: ${this.socket.userId}`)
|
||||
} catch (error: any) {
|
||||
this.logger.error('login error: ' + error.message)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user