Skip to content

A self-hosted media server and file management system

fix: login page calls auth twice before navigation and has a large payload, making it feel slow and buggy

aminnausin189619c91703
diff --git a/resources/js/components/panels/DropdownMenuItems.ts b/resources/js/components/panels/DropdownMenuItems.ts
index 6e7af65b..d22294aa 100644
--- a/resources/js/components/panels/DropdownMenuItems.ts
+++ b/resources/js/components/panels/DropdownMenuItems.ts
@@ -6,6 +6,7 @@ import { handleStartTask } from '@/service/taskService';
import { useAppStore } from '@/stores/AppStore';
import { storeToRefs } from 'pinia';
import { h, computed } from 'vue';
+import { useRoute } from 'vue-router';
import { useAuth } from '@/composables/auth/useAuth';
import { FLAGS } from '@/config/featureFlags';
@@ -36,6 +37,8 @@ export function useDropdownMenuItems() {
const { stateDirectory } = storeToRefs(useContentStore());
const { isAdmin } = useAuth();
+ const route = useRoute();
+
const taskIcons = computed(() => {
const loadingIcon = h(ProiconsSpinner, { class: 'animate-spin' });
@@ -65,7 +68,7 @@ export function useDropdownMenuItems() {
{ ...defaults, name: 'explore', url: '/home', text: 'Explore (experimental)', icon: ProiconsCompass },
],
[
- { ...defaults, name: 'login', url: '/login', text: 'Log in', icon: LucideLogIn },
+ { ...defaults, name: 'login', url: `/login?redirect=${encodeURIComponent(route.fullPath)}`, text: 'Log in', icon: LucideLogIn },
{ ...defaults, name: 'register', url: '/register', text: 'Sign up', icon: LucideUserPlus },
],
];
diff --git a/resources/js/router/index.ts b/resources/js/router/index.ts
index 290e3b0c..6ed8acdf 100644
--- a/resources/js/router/index.ts
+++ b/resources/js/router/index.ts
@@ -1,6 +1,7 @@
import type { NavigationGuardNext, RouteLocationNormalizedGeneric, RouteLocationNormalizedLoadedGeneric } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';
+import { resetUserDependantQueries } from '@/service/vue-query';
import { useContentStore } from '@/stores/ContentStore';
import { useAuthStore } from '@/stores/AuthStore';
import { toTitleCase } from '@/service/util';
@@ -8,6 +9,7 @@ import { logout } from '@/service/authAPI';
import { toast } from '@aminnausin/cedar-ui';
import ErrorView from '@/views/ErrorView.vue';
+import LoginView from '@/views/LoginView.vue';
import nProgress from 'nprogress';
interface RouteMeta {
@@ -43,7 +45,7 @@ export const router = createRouter({
{
path: '/login',
name: 'login',
- component: () => import('@/views/LoginView.vue'),
+ component: LoginView,
meta: { guestOnly: true },
},
{
@@ -67,7 +69,7 @@ export const router = createRouter({
{
path: '/logout',
name: 'logout',
- beforeEnter: async (to, from, next) => {
+ beforeEnter: async (_, from, next) => {
const authStore = useAuthStore();
const contentStore = useContentStore();
const meta = from.meta as { title?: string; protected?: boolean };
@@ -84,6 +86,8 @@ export const router = createRouter({
toast.error(`Unable to logout.`);
console.error(error);
}
+
+ await resetUserDependantQueries();
}
authStore.clearAuthState();
@@ -216,7 +220,7 @@ const redirectAfterLogin = async (to: RouteLocationNormalizedGeneric, next: Navi
const redirectGuest = async (to: RouteLocationNormalizedGeneric, from: RouteLocationNormalizedLoadedGeneric, next: NavigationGuardNext) => {
const authStore = useAuthStore();
- if (authStore.userData || (await authStore.fetchUser())) {
+ if (authStore.userData || (await authStore.fetchUser(false))) {
return next({ path: '/' });
}