mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-09 05:20:05 +00:00
feat: login for web with server type SASJS
This commit is contained in:
23
src/request/SasjsRequestClient.ts
Normal file
23
src/request/SasjsRequestClient.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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)
|
||||
accessToken = localStorage.getItem('accessToken') ?? undefined
|
||||
|
||||
if (accessToken) headers.Authorization = `Bearer ${accessToken}`
|
||||
|
||||
return headers
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user