Parcourir la source

refactor: Migrated user auth data watcher in router beforeEach from VueX to Pinia

Kristian Vos il y a 2 ans
Parent
commit
dbb1fb6df4
1 fichiers modifiés avec 14 ajouts et 8 suppressions
  1. 14 8
      frontend/src/main.ts

+ 14 - 8
frontend/src/main.ts

@@ -268,14 +268,20 @@ router.beforeEach((to, from, next) => {
 
 		if (userAuthStore.gotData) gotData();
 		else {
-			// TODO
-			// const watcher = store.watch(
-			// 	state => userAuthStore.gotData,
-			// 	() => {
-			// 		watcher();
-			// 		gotData();
-			// 	}
-			// );
+			const unsubscribe = userAuthStore.$onAction(
+				({ name, after, onError }) => {
+					if (name === "authData") {
+						after(() => {
+							gotData();
+							unsubscribe();
+						});
+
+						onError(() => {
+							unsubscribe();
+						});
+					}
+				}
+			);
 		}
 	} else next();
 });