Quellcode durchsuchen

fix: Not logging in other open tabs automatically

Owen Diffey vor 3 Jahren
Ursprung
Commit
b68fa0e39a
2 geänderte Dateien mit 26 neuen und 4 gelöschten Zeilen
  1. 16 1
      frontend/src/App.vue
  2. 10 3
      frontend/src/store/modules/user.js

+ 16 - 1
frontend/src/App.vue

@@ -47,7 +47,8 @@ export default {
 			socketConnected: true,
 			keyIsDown: false,
 			scrollPosition: { y: 0, x: 0 },
-			aModalIsOpen2: false
+			aModalIsOpen2: false,
+			broadcastChannel: null
 		};
 	},
 	computed: {
@@ -107,6 +108,20 @@ export default {
 				if (e.matches === !this.nightmode) this.toggleNightMode();
 			});
 
+		if (!this.loggedIn) {
+			lofig.get("cookie.SIDname").then(sid => {
+				this.broadcastChannel = new BroadcastChannel(
+					`${sid}.user_login`
+				);
+				this.broadcastChannel.onmessage = data => {
+					if (data) {
+						this.broadcastChannel.close();
+						window.location.reload();
+					}
+				};
+			});
+		}
+
 		document.onkeydown = ev => {
 			const event = ev || window.event;
 			const { keyCode } = event;

+ 10 - 3
frontend/src/store/modules/user.js

@@ -92,12 +92,19 @@ const modules = {
 			login: ({ commit }, user) =>
 				new Promise((resolve, reject) => {
 					auth.login(user)
-						.then(() =>
+						.then(() => {
+							lofig.get("cookie.SIDname").then(sid => {
+								const bc = new BroadcastChannel(
+									`${sid}.user_login`
+								);
+								bc.postMessage(true);
+								bc.close();
+							});
 							resolve({
 								status: "success",
 								message: "Logged in!"
-							})
-						)
+							});
+						})
 						.catch(err => reject(new Error(err.message)));
 				}),
 			logout: () =>