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

Code before:
			} catch {
				accountability = null;
				expires_at = null;
			}
		}

		if (!token || !accountability || !accountability.user) {
			logger.debug('WebSocket upgrade denied - ' + JSON.stringify(accountability || 'invalid'));
			socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
			socket.destroy();
			return;
		}

		try {
			this.checkUserRequirements(accountability);
		} catch {
			logger.debug('WebSocket upgrade denied - ' + JSON.stringify(accountability || 'invalid'));
			socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
			socket.destroy();
			return;
		}

		accountability.ip = accountabilityOverrides.ip;
		accountability.userAgent = accountabilityOverrides.userAgent;
		accountability.origin = accountabilityOverrides.origin;

		this.server.handleUpgrade(request, socket, head, async (ws) => {
			this.catchInvalidMessages(ws);
			const state = { accountability, expires_at } as AuthenticationState;
			this.server.emit('connection', ws, state);
		});
	}

	protected async handleHandshakeUpgrade({ request, socket, head, accountabilityOverrides }: UpgradeContext) {
		this.server.handleUpgrade(request, socket, head, async (ws) => {
			this.catchInvalidMessages(ws);

			try {
				const payload = await waitForAnyMessage(ws, this.authentication.timeout);
				if (getMessageType(payload) !== 'auth') throw new Error();

				const state = await authenticateConnection(WebSocketAuthMessage.parse(payload));

				if (state.accountability) {
					state.accountability.ip = accountabilityOverrides.ip;
					state.accountability.userAgent = accountabilityOverrides.userAgent;
					state.accountability.origin = accountabilityOverrides.origin;
				}

				this.checkUserRequirements(state.accountability);


Review comment (suggestion):

```suggestion
		Object.assign(accountability, accountabilityOverrides);
```

Code after:
			} catch {
				accountability = null;
				expires_at = null;
			}
		}

		if (!token || !accountability || !accountability.user) {
			logger.debug('WebSocket upgrade denied - ' + JSON.stringify(accountability || 'invalid'));
			socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
			socket.destroy();
			return;
		}

		try {
			this.checkUserRequirements(accountability);
		} catch {
			logger.debug('WebSocket upgrade denied - ' + JSON.stringify(accountability || 'invalid'));
			socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
			socket.destroy();
			return;
		}

		Object.assign(accountability, accountabilityOverrides);

		this.server.handleUpgrade(request, socket, head, async (ws) => {
			this.catchInvalidMessages(ws);
			const state = { accountability, expires_at } as AuthenticationState;
			this.server.emit('connection', ws, state);
		});
	}

	protected async handleHandshakeUpgrade({ request, socket, head, accountabilityOverrides }: UpgradeContext) {
		this.server.handleUpgrade(request, socket, head, async (ws) => {
			this.catchInvalidMessages(ws);

			try {
				const payload = await waitForAnyMessage(ws, this.authentication.timeout);
				if (getMessageType(payload) !== 'auth') throw new Error();

				const state = await authenticateConnection(WebSocketAuthMessage.parse(payload));

				if (state.accountability) {
					Object.assign(state.accountability, accountabilityOverrides);
				}

				this.checkUserRequirements(state.accountability);

				ws.send(authenticationSuccess(payload['uid'], state.refresh_token));

				this.server.emit('connection', ws, state);
			} catch {