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
148c81e3
Commit
148c81e3
authored
Sep 13, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use cookie names
parent
a7858ab6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
2 deletions
+6
-2
fetch.ts
lib/api/fetch.ts
+3
-1
cookies.ts
lib/cookies.ts
+1
-0
middleware.js
middleware.js
+2
-1
No files found.
lib/api/fetch.ts
View file @
148c81e3
...
@@ -2,6 +2,8 @@ import type { NextApiRequest } from 'next';
...
@@ -2,6 +2,8 @@ import type { NextApiRequest } from 'next';
import
type
{
RequestInit
,
Response
}
from
'
node-fetch
'
;
import
type
{
RequestInit
,
Response
}
from
'
node-fetch
'
;
import
nodeFetch
from
'
node-fetch
'
;
import
nodeFetch
from
'
node-fetch
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
// first arg can be only a string
// first arg can be only a string
// FIXME migrate to RequestInfo later if needed
// FIXME migrate to RequestInfo later if needed
export
default
function
fetchFactory
(
_req
:
NextApiRequest
)
{
export
default
function
fetchFactory
(
_req
:
NextApiRequest
)
{
...
@@ -9,7 +11,7 @@ export default function fetchFactory(_req: NextApiRequest) {
...
@@ -9,7 +11,7 @@ export default function fetchFactory(_req: NextApiRequest) {
const
headers
=
{
const
headers
=
{
accept
:
'
application/json
'
,
accept
:
'
application/json
'
,
'
content-type
'
:
'
application/json
'
,
'
content-type
'
:
'
application/json
'
,
cookie
:
`
_explorer_key=
${
_req
.
cookies
.
_explorer_key
}
`
,
cookie
:
`
${
cookies
.
NAMES
.
API_TOKEN
}
=
${
_req
.
cookies
[
cookies
.
NAMES
.
API_TOKEN
]
}
`
,
};
};
const
url
=
`https://blockscout.com
${
path
}
`
;
const
url
=
`https://blockscout.com
${
path
}
`
;
...
...
lib/cookies.ts
View file @
148c81e3
...
@@ -7,6 +7,7 @@ export enum NAMES {
...
@@ -7,6 +7,7 @@ export enum NAMES {
NAV_BAR_COLLAPSED
=
'
nav_bar_collapsed
'
,
NAV_BAR_COLLAPSED
=
'
nav_bar_collapsed
'
,
NETWORK_TYPE
=
'
network_type
'
,
NETWORK_TYPE
=
'
network_type
'
,
NETWORK_SUB_TYPE
=
'
network_sub_type
'
,
NETWORK_SUB_TYPE
=
'
network_sub_type
'
,
API_TOKEN
=
'
_explorer_key
'
,
}
}
export
function
get
(
name
?:
string
|
undefined
|
null
)
{
export
function
get
(
name
?:
string
|
undefined
|
null
)
{
...
...
middleware.js
View file @
148c81e3
const
{
NextResponse
}
=
require
(
'
next/server
'
);
const
{
NextResponse
}
=
require
(
'
next/server
'
);
const
{
NAMES
}
=
require
(
'
lib/cookies
'
);
const
NETWORKS
=
require
(
'
lib/networks/availableNetworks
'
).
default
;
const
NETWORKS
=
require
(
'
lib/networks/availableNetworks
'
).
default
;
export
function
middleware
(
req
)
{
export
function
middleware
(
req
)
{
...
@@ -8,7 +9,7 @@ export function middleware(req) {
...
@@ -8,7 +9,7 @@ export function middleware(req) {
type
===
networkType
&&
(
subType
?
subType
===
networkSubtype
:
true
));
type
===
networkType
&&
(
subType
?
subType
===
networkSubtype
:
true
));
if
(
selectedNetwork
)
{
if
(
selectedNetwork
)
{
const
apiToken
=
req
.
cookies
.
get
(
'
_explorer_key
'
);
const
apiToken
=
req
.
cookies
.
get
(
NAMES
.
API_TOKEN
);
if
(
!
apiToken
)
{
if
(
!
apiToken
)
{
const
authPath
=
`/
${
selectedNetwork
.
type
}
/
${
selectedNetwork
.
subType
}
auth/auth0`
;
const
authPath
=
`/
${
selectedNetwork
.
type
}
/
${
selectedNetwork
.
subType
}
auth/auth0`
;
...
...
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