Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
29d72d6a
Commit
29d72d6a
authored
May 31, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add Authorization header for external services APIs
parent
8e11098f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
2 deletions
+12
-2
nodeFetch.ts
lib/api/nodeFetch.ts
+3
-0
resources.ts
lib/api/resources.ts
+5
-0
useApiFetch.tsx
lib/api/useApiFetch.tsx
+4
-2
No files found.
lib/api/nodeFetch.ts
View file @
29d72d6a
...
...
@@ -14,11 +14,14 @@ export default function fetchFactory(
// FIXME migrate to RequestInfo later if needed
return
function
fetch
(
url
:
string
,
init
?:
RequestInit
):
Promise
<
Response
>
{
const
csrfToken
=
_req
.
headers
[
'
x-csrf-token
'
];
const
authToken
=
_req
.
headers
[
'
Authorization
'
];
const
headers
=
{
accept
:
_req
.
headers
[
'
accept
'
]
||
'
application/json
'
,
'
content-type
'
:
_req
.
headers
[
'
content-type
'
]
||
'
application/json
'
,
cookie
:
`
${
cookies
.
NAMES
.
API_TOKEN
}
=
${
_req
.
cookies
[
cookies
.
NAMES
.
API_TOKEN
]
}
`
,
...(
csrfToken
?
{
'
x-csrf-token
'
:
String
(
csrfToken
)
}
:
{}),
...(
authToken
?
{
Authorization
:
String
(
authToken
)
}
:
{}),
};
httpLogger
.
logger
.
info
({
...
...
lib/api/resources.ts
View file @
29d72d6a
...
...
@@ -65,6 +65,7 @@ export interface ApiResource {
endpoint
?:
string
;
basePath
?:
string
;
pathParams
?:
Array
<
string
>
;
needAuth
?:
boolean
;
// for external APIs which require authentication
}
export
const
RESOURCES
=
{
...
...
@@ -109,6 +110,7 @@ export const RESOURCES = {
pathParams
:
[
'
chainId
'
as
const
,
'
type
'
as
const
],
endpoint
:
appConfig
.
contractInfoApi
.
endpoint
,
basePath
:
appConfig
.
contractInfoApi
.
basePath
,
needAuth
:
true
,
},
verified_addresses
:
{
...
...
@@ -116,6 +118,7 @@ export const RESOURCES = {
pathParams
:
[
'
chainId
'
as
const
],
endpoint
:
appConfig
.
contractInfoApi
.
endpoint
,
basePath
:
appConfig
.
contractInfoApi
.
basePath
,
needAuth
:
true
,
},
token_info_applications_config
:
{
...
...
@@ -123,6 +126,7 @@ export const RESOURCES = {
pathParams
:
[
'
chainId
'
as
const
],
endpoint
:
appConfig
.
adminServiceApi
.
endpoint
,
basePath
:
appConfig
.
adminServiceApi
.
basePath
,
needAuth
:
true
,
},
token_info_applications
:
{
...
...
@@ -130,6 +134,7 @@ export const RESOURCES = {
pathParams
:
[
'
chainId
'
as
const
,
'
id
'
as
const
],
endpoint
:
appConfig
.
adminServiceApi
.
endpoint
,
basePath
:
appConfig
.
adminServiceApi
.
basePath
,
needAuth
:
true
,
},
// STATS
...
...
lib/api/useApiFetch.tsx
View file @
29d72d6a
import
React
from
'
react
'
;
import
isNeedProxy
from
'
lib/api/isNeedProxy
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
type
{
Params
as
FetchParams
}
from
'
lib/hooks/useFetch
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
...
...
@@ -27,9 +28,10 @@ export default function useApiFetch() {
url
,
{
credentials
:
'
include
'
,
...(
resource
.
endpoint
&&
isNeedProxy
()
?
{
...(
resource
.
endpoint
?
{
headers
:
{
'
x-endpoint
'
:
resource
.
endpoint
,
...(
isNeedProxy
()
?
{
'
x-endpoint
'
:
resource
.
endpoint
}
:
{}),
...(
resource
.
needAuth
?
{
Authorization
:
cookies
.
get
(
cookies
.
NAMES
.
API_TOKEN
)
}
:
{}),
},
}
:
{}),
...
fetchParams
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment