From e6168e11ff3906df564da398e9c47ec95d1a5429 Mon Sep 17 00:00:00 2001
From: VIktorGrev <viktog2210@gmail.com>
Date: Fri, 26 Apr 2024 11:30:05 +0200
Subject: [PATCH] feat: Cookie -> Session

---
 src/main.ts                      | 19 +++++++------------
 src/router/index.ts              |  2 +-
 src/stores/ConfigurationStore.ts |  8 +++-----
 src/stores/UserStore.ts          |  5 -----
 tsconfig.json                    |  4 +++-
 5 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/src/main.ts b/src/main.ts
index c97fa3b..ebb6e70 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,19 +1,14 @@
-import './assets/main.css'
-
-import { createApp } from 'vue'
-import { createPinia } from 'pinia'
-import piniaPersist from 'pinia-plugin-persist';
-
-import App from './App.vue'
-import router from './router'
+import { createApp } from 'vue';
+import { createPinia } from 'pinia';
 
+import App from './App.vue';
+import router from './router';
 import 'bootstrap/dist/css/bootstrap.min.css';
 import 'bootstrap';
 
 const app = createApp(App);
 const pinia = createPinia();
-pinia.use(piniaPersist);
 
-app.use(pinia)
-app.use(router)
-app.mount('#app')
+app.use(pinia);
+app.use(router);
+app.mount('#app');
diff --git a/src/router/index.ts b/src/router/index.ts
index 53e86ec..7620b65 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -203,7 +203,7 @@ const router = createRouter({
 router.beforeEach((to, from, next) => {
   const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
   const requiresAdmin = to.matched.some(record => record.meta.requiresAdmin);
-  let user = useUserInfoStore();
+  const user= useUserInfoStore();
   const userRole = user.role;
   const isAuthenticated = user.isLoggedIn;
 
diff --git a/src/stores/ConfigurationStore.ts b/src/stores/ConfigurationStore.ts
index fb9e0dd..951538a 100644
--- a/src/stores/ConfigurationStore.ts
+++ b/src/stores/ConfigurationStore.ts
@@ -3,7 +3,7 @@ export const useConfigurationStore = defineStore('ConfigurationStore', {
   state: () => ({
     commitment: '',
     experience: '',
-    challenges: []
+    challenges: [] as Array<string>,
   }),
   actions: {
     setCommitment(commitment: string) {
@@ -28,11 +28,9 @@ export const useConfigurationStore = defineStore('ConfigurationStore', {
     getExperience(): string {
       return this.experience
     },
-    getChallenges(): string {
+    getChallenges(): Array<string> {
       return this.challenges
     }
   },
-  persist: {
-    enabled: true,
-  }
+
 });
diff --git a/src/stores/UserStore.ts b/src/stores/UserStore.ts
index 5622d43..4d5fbd6 100644
--- a/src/stores/UserStore.ts
+++ b/src/stores/UserStore.ts
@@ -2,7 +2,6 @@ import { OpenAPI } from '@/api';
 import Cookies from 'js-cookie';
 import { defineStore } from 'pinia';
 
-
 const cookiesStorage: Storage = {
   setItem(key, state) {
     return Cookies.set(key, state, { expires: 3 });
@@ -88,8 +87,4 @@ export const useUserInfoStore = defineStore('UserInfoStore', {
       return this.accessToken !== '';
     },
   },
-  persist: {
-    enabled: true,
-    strategies: [{ key: 'userInfo', storage: cookiesStorage }]
-  },
 });
\ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
index 5304731..90465d0 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -12,6 +12,8 @@
     }
   ],
   "compilerOptions": {
-    "module": "NodeNext"
+    "module": "NodeNext",
+    "types" : ["pinia-plugin-persist"],
+    "typeRoots": ["./node_modules/@types", "./node_modules/pinia-plugin-persist/dist"]
   }
 }
-- 
GitLab