diff --git a/src/store/user.ts b/src/store/user.ts index f444b6e..e9cf78d 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -63,6 +63,11 @@ export function useCurrentUser() { localStorage.clear() } + function onInvalidAuthToken() { + setCurrentUser(null) + clearAuthToken() + } + return { currentUser, ensureCurrentUser, @@ -72,5 +77,6 @@ export function useCurrentUser() { setAuthToken, isAuthenticated, endUserSession, + onInvalidAuthToken, } } diff --git a/src/views/HomeTimeline.vue b/src/views/HomeTimeline.vue index d380671..a2817a4 100644 --- a/src/views/HomeTimeline.vue +++ b/src/views/HomeTimeline.vue @@ -26,7 +26,7 @@ import SidebarLayout from "@/components/SidebarLayout.vue" import { useCurrentUser } from "@/store/user" const router = useRouter() -const { endUserSession, ensureAuthToken, ensureCurrentUser } = useCurrentUser() +const { onInvalidAuthToken, ensureAuthToken, ensureCurrentUser } = useCurrentUser() let posts = $ref([]) let isLoading = $ref(false) @@ -46,8 +46,9 @@ async function loadTimeline() { try { posts = await getHomeTimeline(authToken) } catch (error: any) { + console.error("timeline loading error:", error.message) if (error.message === "access token is invalid") { - await endUserSession() + onInvalidAuthToken() router.push({ name: "landing-page" }) return } else {