diff --git a/src/App.vue b/src/App.vue
index 5842e29..385415e 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -7,6 +7,7 @@
+
+
+
diff --git a/src/serverCom.ts b/src/serverCom.ts
index e6bdf38..e33717e 100644
--- a/src/serverCom.ts
+++ b/src/serverCom.ts
@@ -1,6 +1,7 @@
import axios from "axios";
import { isAuthenticatedPromise, type Payload } from "./router/authGuard";
import router from "./router";
+import { useNotificationStore } from "./stores/notification";
let devMode = process.env.NODE_ENV === "development";
@@ -37,7 +38,7 @@ http.interceptors.response.use(
return response;
},
async (error) => {
- if (!error.config.url.includes("/admin")) {
+ if (!error.config.url.includes("/admin") || !error.config.url.includes("/user")) {
return Promise.reject(error);
}
@@ -53,6 +54,9 @@ http.interceptors.response.use(
.catch();
}
+ const notificationStore = useNotificationStore();
+ notificationStore.push("Fehler", error.response.data, "error");
+
return Promise.reject(error);
}
);
diff --git a/src/stores/notification.ts b/src/stores/notification.ts
new file mode 100644
index 0000000..249f2c0
--- /dev/null
+++ b/src/stores/notification.ts
@@ -0,0 +1,46 @@
+import { defineStore } from "pinia";
+
+export interface Notification {
+ id: number;
+ title: string;
+ text: string;
+ type: NotificationType;
+ indicator: boolean;
+}
+
+export type NotificationType = "info" | "warning" | "error";
+
+export const useNotificationStore = defineStore("notification", {
+ state: () => {
+ return {
+ notifications: [] as Array,
+ timeouts: {} as { [key: string]: any },
+ };
+ },
+ actions: {
+ push(title: string, text: string, type: NotificationType, timeout: number = 5000) {
+ let id = Date.now();
+ this.notifications.push({
+ id,
+ title,
+ text,
+ type,
+ indicator: false,
+ });
+ setTimeout(() => {
+ this.notifications[this.notifications.findIndex((n) => n.id === id)].indicator = true;
+ }, 100);
+ this.timeouts[id] = setTimeout(() => {
+ this.revoke(id);
+ }, timeout);
+ },
+ revoke(id: number) {
+ this.notifications.splice(
+ this.notifications.findIndex((n) => n.id === id),
+ 1
+ );
+ clearTimeout(this.timeouts[id]);
+ delete this.timeouts[id];
+ },
+ },
+});