Skip to content

Commit

Permalink
fix(datastores): use auth token for history request if available
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Aug 14, 2022
1 parent a1895fd commit cf1ce0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class TimelineController {
private async fetchMoreTransactions() {
const publishedId = this.timeline.publishedId
const draftId = this.timeline.draftId
const dataset = this.client.config().dataset
const {dataset, token} = this.client.config()
const limit = TRANSLOG_ENTRY_LIMIT

let queryParams = `tag=sanity.studio.desk.history&effectFormat=mendoza&excludeContent=true&excludeMutations=true&includeIdentifiedDocumentsOnly=true&reverse=true&limit=${limit}`
Expand All @@ -271,7 +271,7 @@ export class TimelineController {

const url = `/data/history/${dataset}/transactions/${publishedId},${draftId}?${queryParams}`

const stream = await getJsonStream(this.client.getUrl(url))
const stream = await getJsonStream(this.client.getUrl(url), token)
const reader = stream.getReader()
let count = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import type {TransactionLogEventWithEffects} from '@sanity/types'

type StreamResult = TransactionLogEventWithEffects | {error: {description?: string; type: string}}

export async function getJsonStream(url: string): Promise<ReadableStream<StreamResult>> {
const options: RequestInit = {credentials: 'include'}
export async function getJsonStream(
url: string,
token: string | undefined
): Promise<ReadableStream<StreamResult>> {
const options: RequestInit = token
? {headers: {Authorization: `Bearer ${token}`}}
: {credentials: 'include'}
const response = await fetch(url, options)
return getStream(response)
}
Expand Down

0 comments on commit cf1ce0d

Please sign in to comment.