From 1cf60ee081250bb646149aef1f1dc80bcd175e2a Mon Sep 17 00:00:00 2001
From: Erik Borgeteien Hansen <erik@erikbhan.no>
Date: Thu, 5 May 2022 15:35:46 +0200
Subject: [PATCH] add adminlist to state when logging in

---
 src/components/UserAuthComponents/LoginForm.vue    | 3 +++
 src/components/UserAuthComponents/RegisterForm.vue | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/components/UserAuthComponents/LoginForm.vue b/src/components/UserAuthComponents/LoginForm.vue
index 4b52c2e..f13178c 100644
--- a/src/components/UserAuthComponents/LoginForm.vue
+++ b/src/components/UserAuthComponents/LoginForm.vue
@@ -94,6 +94,7 @@ import useVuelidate from "@vuelidate/core";
 import { required, email, helpers } from "@vuelidate/validators";
 import { doLogin } from "@/utils/apiutil";
 import Button from "@/components/BaseComponents/ColoredButton";
+import UserService from "@/services/user.service";
 
 export default {
   name: "LoginForm.vue",
@@ -151,6 +152,8 @@ export default {
         this.message = "Feil e-post/passord";
       } else if (loginResponse.isLoggedIn === true) {
         this.$store.commit("saveToken", loginResponse.token);
+        const adminList = await UserService.getAdminList();
+        this.$store.commit("addAdminList", adminList);
         await this.$router.push("/");
       }
     },
diff --git a/src/components/UserAuthComponents/RegisterForm.vue b/src/components/UserAuthComponents/RegisterForm.vue
index 17cd3cf..5750368 100644
--- a/src/components/UserAuthComponents/RegisterForm.vue
+++ b/src/components/UserAuthComponents/RegisterForm.vue
@@ -175,6 +175,7 @@ import {
   helpers,
 } from "@vuelidate/validators";
 import Button from "@/components/BaseComponents/ColoredButton";
+import UserService from "@/services/user.service";
 
 // const isEmailTaken = (value) =>
 // fetch(`/api/unique/${value}`).then((r) => r.json()); // check the email in the server
@@ -263,8 +264,10 @@ export default {
         await this.$router.push("/login");
         return;
       }
-
+      UserService.addAdminsToState();
       this.$store.commit("saveToken", loginResponse.token);
+      const adminList = await UserService.getAdminList();
+      this.$store.commit("addAdminList", adminList);
       await this.$router.push("/");
     },
     async sendRegisterRequest() {
-- 
GitLab