Skip to content

Commit

Permalink
fix: authorize API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Oct 13, 2023
1 parent eec67c0 commit b53f124
Show file tree
Hide file tree
Showing 3 changed files with 766 additions and 746 deletions.
10 changes: 8 additions & 2 deletions composables/usePosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useUserSettings } from '~/composables/useUserSettings'
import { toast } from 'vue-sonner'
import { IPostPage } from 'assets/js/post'

const { token: authToken } = useAuth()

const userSettings = useUserSettings()

export function usePosts(initialPostPages: Ref<IPostPage[] | null>) {
Expand Down Expand Up @@ -92,11 +94,15 @@ export function usePosts(initialPostPages: Ref<IPostPage[] | null>) {
console.debug('There is no next page')
}

const postsPage = await $fetch(links.next)
const postsPage = await $fetch(links.next, {
headers: {
'Authorization': authToken.value
}
})
//
.catch((error) => {
console.error(error)
toast.error(`Failed to load next posts: "${error.message}"`)
toast.error(`Failed to load next posts: "${ error.message }"`)
})

initialPostPages.value.push(postsPage)
Expand Down
Loading

0 comments on commit b53f124

Please sign in to comment.