Browse Source

fix(Station): Changing privacy does not kick out newly-unauthorized users

Owen Diffey 2 years ago
parent
commit
aea4d61499
1 changed files with 28 additions and 23 deletions
  1. 28 23
      frontend/src/pages/Station/index.vue

+ 28 - 23
frontend/src/pages/Station/index.vue

@@ -1121,32 +1121,37 @@ export default {
 		});
 
 		this.socket.on("event:station.updated", async res => {
-			const { name, theme } = res.data.station;
-
-			if (this.station.name !== name) {
-				await this.$router.push(
-					`${name}?${Object.keys(this.$route.query)
-						.map(
-							key =>
-								`${encodeURIComponent(
-									key
-								)}=${encodeURIComponent(
-									this.$route.query[key]
-								)}`
-						)
-						.join("&")}`
-				);
+			const { name, theme, privacy } = res.data.station;
 
-				// eslint-disable-next-line no-restricted-globals
-				history.replaceState({ ...history.state, ...{} }, null);
-			}
+			if (!this.isOwnerOrAdmin() && privacy === "private") {
+				window.location.href =
+					"/?msg=The station you were in was made private.";
+			} else {
+				if (this.station.name !== name) {
+					await this.$router.push(
+						`${name}?${Object.keys(this.$route.query)
+							.map(
+								key =>
+									`${encodeURIComponent(
+										key
+									)}=${encodeURIComponent(
+										this.$route.query[key]
+									)}`
+							)
+							.join("&")}`
+					);
+
+					// eslint-disable-next-line no-restricted-globals
+					history.replaceState({ ...history.state, ...{} }, null);
+				}
 
-			if (this.station.theme !== theme)
-				document.getElementsByTagName(
-					"html"
-				)[0].style.cssText = `--primary-color: var(--${theme})`;
+				if (this.station.theme !== theme)
+					document.getElementsByTagName(
+						"html"
+					)[0].style.cssText = `--primary-color: var(--${theme})`;
 
-			this.updateStation(res.data.station);
+				this.updateStation(res.data.station);
+			}
 		});
 
 		this.socket.on("event:station.users.updated", res =>