Don't revoke auth token when handling timeline loading error

This commit is contained in:
silverpill 2023-03-25 00:24:33 +00:00
parent 7b6f8a2322
commit 5cb76f9dbe
2 changed files with 9 additions and 2 deletions

View file

@ -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,
}
}

View file

@ -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<Post[]>([])
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 {