mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-05 03:30:05 +00:00
24 lines
689 B
TypeScript
24 lines
689 B
TypeScript
import { RequestClient } from './RequestClient'
|
|
|
|
/**
|
|
* Specific request client for SASJS.
|
|
* Append tokens in headers.
|
|
*/
|
|
export class SasjsRequestClient extends RequestClient {
|
|
getHeaders = (accessToken: string | undefined, contentType: string) => {
|
|
const headers: any = {}
|
|
|
|
if (contentType !== 'application/x-www-form-urlencoded')
|
|
headers['Content-Type'] = contentType
|
|
|
|
headers.Accept = contentType === 'application/json' ? contentType : '*/*'
|
|
|
|
if (!accessToken && typeof window !== 'undefined')
|
|
accessToken = localStorage.getItem('accessToken') ?? undefined
|
|
|
|
if (accessToken) headers.Authorization = `Bearer ${accessToken}`
|
|
|
|
return headers
|
|
}
|
|
}
|