Don't revoke auth token when handling timeline loading error
This commit is contained in:
parent
7b6f8a2322
commit
5cb76f9dbe
2 changed files with 9 additions and 2 deletions
|
@ -63,6 +63,11 @@ export function useCurrentUser() {
|
||||||
localStorage.clear()
|
localStorage.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onInvalidAuthToken() {
|
||||||
|
setCurrentUser(null)
|
||||||
|
clearAuthToken()
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentUser,
|
currentUser,
|
||||||
ensureCurrentUser,
|
ensureCurrentUser,
|
||||||
|
@ -72,5 +77,6 @@ export function useCurrentUser() {
|
||||||
setAuthToken,
|
setAuthToken,
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
endUserSession,
|
endUserSession,
|
||||||
|
onInvalidAuthToken,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import SidebarLayout from "@/components/SidebarLayout.vue"
|
||||||
import { useCurrentUser } from "@/store/user"
|
import { useCurrentUser } from "@/store/user"
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { endUserSession, ensureAuthToken, ensureCurrentUser } = useCurrentUser()
|
const { onInvalidAuthToken, ensureAuthToken, ensureCurrentUser } = useCurrentUser()
|
||||||
|
|
||||||
let posts = $ref<Post[]>([])
|
let posts = $ref<Post[]>([])
|
||||||
let isLoading = $ref(false)
|
let isLoading = $ref(false)
|
||||||
|
@ -46,8 +46,9 @@ async function loadTimeline() {
|
||||||
try {
|
try {
|
||||||
posts = await getHomeTimeline(authToken)
|
posts = await getHomeTimeline(authToken)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
console.error("timeline loading error:", error.message)
|
||||||
if (error.message === "access token is invalid") {
|
if (error.message === "access token is invalid") {
|
||||||
await endUserSession()
|
onInvalidAuthToken()
|
||||||
router.push({ name: "landing-page" })
|
router.push({ name: "landing-page" })
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue