Fix automatic logout on authentication error

This commit is contained in:
silverpill 2023-03-12 23:36:59 +00:00
parent e3beb705eb
commit 42e3f6d045
3 changed files with 17 additions and 11 deletions

View file

@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Enabled audio and video uploads. - Enabled audio and video uploads.
### Fixed
- Fixed automatic logout on authentication error.
## [1.16.0] - 2023-03-08 ## [1.16.0] - 2023-03-08
### Added ### Added

View file

@ -55,16 +55,7 @@ const emit = defineEmits<{(event: "reload-home"): void}>()
function showHomeTimeline() { function showHomeTimeline() {
if (route.name === "home") { if (route.name === "home") {
try { loadNotifications(ensureAuthToken())
loadNotifications(ensureAuthToken())
} catch (error: any) {
if (error.message === "access token is invalid") {
router.push({ name: "landing-page" })
return
} else {
throw error
}
}
emit("reload-home") emit("reload-home")
} else { } else {
router.push({ name: "home" }) router.push({ name: "home" })

View file

@ -15,6 +15,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted } from "vue" import { onMounted } from "vue"
import { $ref } from "vue/macros" import { $ref } from "vue/macros"
import { useRouter } from "vue-router"
import { Post, getHomeTimeline } from "@/api/posts" import { Post, getHomeTimeline } from "@/api/posts"
import { Permissions } from "@/api/users" import { Permissions } from "@/api/users"
@ -24,6 +25,7 @@ import PostList from "@/components/PostList.vue"
import SidebarLayout from "@/components/SidebarLayout.vue" import SidebarLayout from "@/components/SidebarLayout.vue"
import { useCurrentUser } from "@/store/user" import { useCurrentUser } from "@/store/user"
const router = useRouter()
const { ensureAuthToken, ensureCurrentUser } = useCurrentUser() const { ensureAuthToken, ensureCurrentUser } = useCurrentUser()
let posts = $ref<Post[]>([]) let posts = $ref<Post[]>([])
@ -41,7 +43,16 @@ function insertPost(post: Post) {
async function loadTimeline() { async function loadTimeline() {
isLoading = true isLoading = true
const authToken = ensureAuthToken() const authToken = ensureAuthToken()
posts = await getHomeTimeline(authToken) try {
posts = await getHomeTimeline(authToken)
} catch (error: any) {
if (error.message === "access token is invalid") {
router.push({ name: "landing-page" })
return
} else {
throw error
}
}
isLoading = false isLoading = false
} }