Commit 148c81e3 authored by tom's avatar tom

use cookie names

parent a7858ab6
......@@ -2,6 +2,8 @@ import type { NextApiRequest } from 'next';
import type { RequestInit, Response } from 'node-fetch';
import nodeFetch from 'node-fetch';
import * as cookies from 'lib/cookies';
// first arg can be only a string
// FIXME migrate to RequestInfo later if needed
export default function fetchFactory(_req: NextApiRequest) {
......@@ -9,7 +11,7 @@ export default function fetchFactory(_req: NextApiRequest) {
const headers = {
accept: '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 }`;
......
......@@ -7,6 +7,7 @@ export enum NAMES {
NAV_BAR_COLLAPSED='nav_bar_collapsed',
NETWORK_TYPE='network_type',
NETWORK_SUB_TYPE='network_sub_type',
API_TOKEN='_explorer_key',
}
export function get(name?: string | undefined | null) {
......
const { NextResponse } = require('next/server');
const { NAMES } = require('lib/cookies');
const NETWORKS = require('lib/networks/availableNetworks').default;
export function middleware(req) {
......@@ -8,7 +9,7 @@ export function middleware(req) {
type === networkType && (subType ? subType === networkSubtype : true));
if (selectedNetwork) {
const apiToken = req.cookies.get('_explorer_key');
const apiToken = req.cookies.get(NAMES.API_TOKEN);
if (!apiToken) {
const authPath = `/${ selectedNetwork.type }/${ selectedNetwork.subType }auth/auth0`;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment