Repository: directus/directus
File: api/src/websocket/controllers/base.ts (TypeScript)

Code before:
		this.clients.add(client);
		return client;
	}

	protected parseMessage(data: string): WebSocketMessage {
		let message: WebSocketMessage;

		try {
			message = WebSocketMessage.parse(parseJSON(data));
		} catch {
			throw new WebSocketError('server', 'INVALID_PAYLOAD', 'Unable to parse the incoming message.');
		}

		return message;
	}

	protected async handleAuthRequest(client: WebSocketClient, message: WebSocketAuthMessage) {
		try {
			const accountabilityOverrides = {};

			/**
			 * Re-use the existing ip, userAgent and origin accountability properties.
			 * They are only sent in the original connection request
			 */
			if (client.accountability) {
				Object.assign(accountabilityOverrides, {
					ip: client.accountability.ip,
					userAgent: client.accountability.userAgent,
					origin: client.accountability.origin,
				});
			}

			const { accountability, expires_at, refresh_token } = await authenticateConnection(
				message,
				accountabilityOverrides,
			);

			this.checkUserRequirements(accountability);

			client.accountability = accountability;
			client.expires_at = expires_at;
			this.setTokenExpireTimer(client);
			emitter.emitAction('websocket.auth.success', { client });
			client.send(authenticationSuccess(message.uid, refresh_token));
			logger.trace(`WebSocket#${client.uid} authenticated as ${JSON.stringify(client.accountability)}`);
		} catch (error) {
			logger.trace(`WebSocket#${client.uid} failed authentication`);
			emitter.emitAction('websocket.auth.failure', { client });

			client.accountability = null;
			client.expires_at = null;

Review comment (suggestion):
Since overrides is always an empty object here instead of accountability we do not need `Object.assign`
```suggestion
				accountabilityOverrides = {
```

Code after:
		this.clients.add(client);
		return client;
	}

	protected parseMessage(data: string): WebSocketMessage {
		let message: WebSocketMessage;

		try {
			message = WebSocketMessage.parse(parseJSON(data));
		} catch {
			throw new WebSocketError('server', 'INVALID_PAYLOAD', 'Unable to parse the incoming message.');
		}

		return message;
	}

	protected async handleAuthRequest(client: WebSocketClient, message: WebSocketAuthMessage) {
		try {
			let accountabilityOverrides = {};

			/**
			 * Re-use the existing ip, userAgent and origin accountability properties.
			 * They are only sent in the original connection request
			 */
			if (client.accountability) {
				accountabilityOverrides = {
					ip: client.accountability.ip,
					userAgent: client.accountability.userAgent,
					origin: client.accountability.origin,
				};
			}

			const { accountability, expires_at, refresh_token } = await authenticateConnection(
				message,
				accountabilityOverrides,
			);

			this.checkUserRequirements(accountability);

			client.accountability = accountability;
			client.expires_at = expires_at;
			this.setTokenExpireTimer(client);
			emitter.emitAction('websocket.auth.success', { client });
			client.send(authenticationSuccess(message.uid, refresh_token));
			logger.trace(`WebSocket#${client.uid} authenticated as ${JSON.stringify(client.accountability)}`);
		} catch (error) {
			logger.trace(`WebSocket#${client.uid} failed authentication`);
			emitter.emitAction('websocket.auth.failure', { client });

			client.accountability = null;
			client.expires_at = null;