Created
February 26, 2022 16:50
-
-
Save KristofferTolboll2/2bc9aacb8c7be64fddea524ba2cece18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| async handleConnection(client: Socket) { | |
| this.logger.debug(`${client.id} is connected...`) | |
| // eslint-disable-next-line @typescript-eslint/tslint/config | |
| const token = client.handshake.query?.token | |
| // eslint-disable-next-line @typescript-eslint/tslint/config | |
| const deviceType: string = client.handshake.query?.deviceType || 'WEB' | |
| const ipAddress: string = client.handshake.address || null | |
| if (!token) { | |
| this.logger.log('Unauthorized connection') | |
| client.disconnect(true) | |
| return null | |
| } | |
| // eslint-disable-next-line @typescript-eslint/tslint/config | |
| const userId = await this.authService.findUserIdByRefreshtoken(token) | |
| //TODO: Create activity session for userId | |
| //Create a session for the desired user | |
| const parsedDeviceTypeString = | |
| deviceType.toUpperCase() === 'IOS' ? 'IOS' : deviceType === 'ANDROID' ? 'ANDROID' : null | |
| const parsedDeviceType = DeviceType[parsedDeviceTypeString] || null | |
| //Fail silently if user is not found, for the session | |
| this.sessionService.createSessionFromUserId(userId.userId, ipAddress, parsedDeviceType).catch(error => { | |
| this.logger.error(error) | |
| }) | |
| this.logger.debug(`Created session for userId: ${userId.userId}`) | |
| if (!userId) { | |
| this.logger.log('Invalid token') | |
| client.disconnect(true) | |
| return null | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment