mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
redirect from account if there is no cookie
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
const { NextResponse } = require('next/server');
|
||||
|
||||
const NETWORKS = require('lib/networks/availableNetworks').default;
|
||||
|
||||
export function middleware(req) {
|
||||
const [ , networkType, networkSubtype ] = req.nextUrl.pathname.split('/');
|
||||
const selectedNetwork = NETWORKS.find(({ type, subType }) =>
|
||||
type === networkType && (subType ? subType === networkSubtype : true));
|
||||
|
||||
if (selectedNetwork) {
|
||||
const apiToken = req.cookies.get('_explorer_key');
|
||||
|
||||
if (!apiToken) {
|
||||
const authPath = `/${ selectedNetwork.type }/${ selectedNetwork.subType }auth/auth0`;
|
||||
|
||||
return NextResponse.redirect(new URL(authPath, 'https://blockscout.com/'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: '/:network_type/:network_sub_type/account/:path*',
|
||||
};
|
||||
+1
-1
@@ -23,7 +23,7 @@ const moduleExports = {
|
||||
{
|
||||
source: '/',
|
||||
destination: '/poa/core',
|
||||
permanent: true,
|
||||
permanent: false,
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@
|
||||
"@types/react-dom": "18.0.5",
|
||||
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
||||
"eslint": "8.16.0",
|
||||
"eslint-config-next": "12.1.6",
|
||||
"eslint-config-next": "^12.3.0",
|
||||
"eslint-plugin-es5": "^1.5.0",
|
||||
"eslint-plugin-import-helpers": "^1.2.1",
|
||||
"eslint-plugin-regexp": "^1.7.0",
|
||||
|
||||
@@ -1380,10 +1380,10 @@
|
||||
resolved "https://registry.yarnpkg.com/@next/env/-/env-12.2.5.tgz#d908c57b35262b94db3e431e869b72ac3e1ad3e3"
|
||||
integrity sha512-vLPLV3cpPGjUPT3PjgRj7e3nio9t6USkuew3JE/jMeon/9Mvp1WyR18v3iwnCuX7eUAm1HmAbJHHLAbcu/EJcw==
|
||||
|
||||
"@next/eslint-plugin-next@12.1.6":
|
||||
version "12.1.6"
|
||||
resolved "https://registry.yarnpkg.com/@next/eslint-plugin-next/-/eslint-plugin-next-12.1.6.tgz#dde3f98831f15923b25244588d924c716956292e"
|
||||
integrity sha512-yNUtJ90NEiYFT6TJnNyofKMPYqirKDwpahcbxBgSIuABwYOdkGwzos1ZkYD51Qf0diYwpQZBeVqElTk7Q2WNqw==
|
||||
"@next/eslint-plugin-next@12.3.0":
|
||||
version "12.3.0"
|
||||
resolved "https://registry.yarnpkg.com/@next/eslint-plugin-next/-/eslint-plugin-next-12.3.0.tgz#302c1f03618d5001ce92ea6826c329268759128e"
|
||||
integrity sha512-jVdq1qYTNDjUtulnE8/hkPv0pHILV4jMg5La99iaY/FFm20WxVnsAZtbNnMvlPbf8dc010oO304SX9yXbg5PAw==
|
||||
dependencies:
|
||||
glob "7.1.7"
|
||||
|
||||
@@ -2709,12 +2709,12 @@ escape-string-regexp@^4.0.0:
|
||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"
|
||||
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==
|
||||
|
||||
eslint-config-next@12.1.6:
|
||||
version "12.1.6"
|
||||
resolved "https://registry.yarnpkg.com/eslint-config-next/-/eslint-config-next-12.1.6.tgz#55097028982dce49159d8753000be3916ac55254"
|
||||
integrity sha512-qoiS3g/EPzfCTkGkaPBSX9W0NGE/B1wNO3oWrd76QszVGrdpLggNqcO8+LR6MB0CNqtp9Q8NoeVrxNVbzM9hqA==
|
||||
eslint-config-next@^12.3.0:
|
||||
version "12.3.0"
|
||||
resolved "https://registry.yarnpkg.com/eslint-config-next/-/eslint-config-next-12.3.0.tgz#d887ab2d143fe1a2b308e9321e932a613e610800"
|
||||
integrity sha512-guHSkNyKnTBB8HU35COgAMeMV0E026BiYRYvyEVVaTOeFcnU3i1EI8/Da0Rl7H3Sgua5FEvoA0vYd2s8kdIUXg==
|
||||
dependencies:
|
||||
"@next/eslint-plugin-next" "12.1.6"
|
||||
"@next/eslint-plugin-next" "12.3.0"
|
||||
"@rushstack/eslint-patch" "^1.1.3"
|
||||
"@typescript-eslint/parser" "^5.21.0"
|
||||
eslint-import-resolver-node "^0.3.6"
|
||||
|
||||
Reference in New Issue
Block a user