1
0
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:
Saad Jutt
2021-12-09 17:13:47 +05:00
parent ebe9c2ffeb
commit c56874fe00
8 changed files with 168 additions and 20 deletions

View 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
}
}