Skip to content

A self-hosted media server and file management system

fix clearing all local storage items on logout

aminnausin638f4c1a9e0a
diff --git a/public/js/auth.js b/public/js/auth.js
index e29667e0..15532222 100644
--- a/public/js/auth.js
+++ b/public/js/auth.js
@@ -47,7 +47,7 @@ function logout(){
response.json()
).then(json => {
console.log(json);
- localStorage.clear('auth-token');
+ localStorage.removeItem('auth-token');
if(json.success == true) window.location.href = "/";
}).catch((error) => {
console.log(error);
diff --git a/resources/js/router/index.js b/resources/js/router/index.js
index 4b2391f3..c580b58c 100644
--- a/resources/js/router/index.js
+++ b/resources/js/router/index.js
@@ -6,7 +6,6 @@ import VideoView from '../views/VideoView.vue'
import { createRouter, createWebHistory} from "vue-router";
import { useAuthStore } from "../stores/AuthStore";
-import { storeToRefs } from "pinia";
import { logout } from "../service/authAPI";
import { toTitleCase } from '../service/util';
@@ -36,12 +35,10 @@ const router = createRouter({
try {
const destination = from.fullPath === '/logout' ? '/' : (from?.meta.protected ? '/' : from.fullPath);
const authStore = useAuthStore();
- const { userData } = storeToRefs(authStore);
+ const { clearAuthState } = authStore;
await logout();
-
- localStorage.clear('auth-token');
- userData.value = null;
+ clearAuthState();
router.push(destination);
} catch (error) {
// eslint-disable-next-line no-undef
diff --git a/resources/js/stores/AuthStore.js b/resources/js/stores/AuthStore.js
index a9846e4b..636b452f 100644
--- a/resources/js/stores/AuthStore.js
+++ b/resources/js/stores/AuthStore.js
@@ -45,6 +45,6 @@ export const useAuthStore = defineStore('Auth', () => {
}
return {
- user, userData, auth,
+ user, userData, auth, clearAuthState,
};
});
\ No newline at end of file