Commit f3ecc07e authored by tom's avatar tom

auth route

parent caa24a4f
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { route } from 'nextjs-routes';
import link from 'lib/link/link'; import appConfig from 'configs/app/config';
export default function useLoginUrl() { export default function useLoginUrl() {
const router = useRouter(); const router = useRouter();
return link('auth', {}, { path: router.asPath }); return appConfig.authUrl + route({ pathname: '/auth', query: { path: router.asPath } });
} }
...@@ -28,7 +28,8 @@ export default function link( ...@@ -28,7 +28,8 @@ export default function link(
return paramValue ? `/${ paramValue }` : ''; return paramValue ? `/${ paramValue }` : '';
}); });
const baseUrl = routeName === 'auth' ? appConfig.authUrl : appConfig.baseUrl; // const baseUrl = routeName === 'auth' ? appConfig.authUrl : appConfig.baseUrl;
const baseUrl = appConfig.baseUrl;
const url = new URL(path, baseUrl); const url = new URL(path, baseUrl);
......
...@@ -11,11 +11,10 @@ export type RouteName = keyof typeof ROUTES; ...@@ -11,11 +11,10 @@ export type RouteName = keyof typeof ROUTES;
export const ROUTES = { export const ROUTES = {
// NETWORK MAIN PAGE // NETWORK MAIN PAGE
// todo_tom need full url builder // network_index: {
network_index: { // pattern: PATHS.network_index,
pattern: PATHS.network_index, // crossNetworkNavigation: true,
crossNetworkNavigation: true, // },
},
// ACCOUNT // ACCOUNT
// watchlist: { // watchlist: {
...@@ -43,10 +42,9 @@ export const ROUTES = { ...@@ -43,10 +42,9 @@ export const ROUTES = {
// crossNetworkNavigation: true, // crossNetworkNavigation: true,
// }, // },
// todo_tom need full url builder // tx: {
tx: { // pattern: PATHS.tx,
pattern: PATHS.tx, // },
},
// BLOCKS // BLOCKS
// blocks: { // blocks: {
...@@ -113,9 +111,10 @@ export const ROUTES = { ...@@ -113,9 +111,10 @@ export const ROUTES = {
}, },
// AUTH // AUTH
auth: { // todo_tom need add page to the app
pattern: PATHS.auth, // auth: {
}, // pattern: PATHS.auth,
// },
}; };
// !!! for development purpose only !!! // !!! for development purpose only !!!
......
import type { NextRequest } from 'next/server'; import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import { route } from 'nextjs-routes';
import appConfig from 'configs/app/config'; import appConfig from 'configs/app/config';
import { NAMES } from 'lib/cookies'; import { NAMES } from 'lib/cookies';
import getCspPolicy from 'lib/csp/getCspPolicy'; import getCspPolicy from 'lib/csp/getCspPolicy';
import link from 'lib/link/link';
const cspPolicy = getCspPolicy(); const cspPolicy = getCspPolicy();
...@@ -22,7 +22,7 @@ export function middleware(req: NextRequest) { ...@@ -22,7 +22,7 @@ export function middleware(req: NextRequest) {
const apiToken = req.cookies.get(NAMES.API_TOKEN); const apiToken = req.cookies.get(NAMES.API_TOKEN);
if ((isAccountRoute || isProfileRoute) && !apiToken && appConfig.isAccountSupported) { if ((isAccountRoute || isProfileRoute) && !apiToken && appConfig.isAccountSupported) {
const authUrl = link('auth', undefined, { path: req.nextUrl.pathname }); const authUrl = appConfig.authUrl + route({ pathname: '/auth', query: { path: req.nextUrl.pathname } });
return NextResponse.redirect(authUrl); return NextResponse.redirect(authUrl);
} }
......
import type { NextPage } from 'next';
const AuthPage: NextPage = () => {
return null;
};
export default AuthPage;
export async function getServerSideProps() {
return {
notFound: true,
};
}
...@@ -18,6 +18,7 @@ declare module "nextjs-routes" { ...@@ -18,6 +18,7 @@ declare module "nextjs-routes" {
| StaticRoute<"/api/proxy"> | StaticRoute<"/api/proxy">
| DynamicRoute<"/apps/[id]", { "id": string }> | DynamicRoute<"/apps/[id]", { "id": string }>
| StaticRoute<"/apps"> | StaticRoute<"/apps">
| StaticRoute<"/auth">
| StaticRoute<"/auth/profile"> | StaticRoute<"/auth/profile">
| DynamicRoute<"/block/[height]", { "height": string }> | DynamicRoute<"/block/[height]", { "height": string }>
| StaticRoute<"/blocks"> | StaticRoute<"/blocks">
......
import { Box, Center, useColorMode } from '@chakra-ui/react'; import { Box, Center, useColorMode } from '@chakra-ui/react';
import { route } from 'nextjs-routes';
import React, { useCallback, useEffect, useRef, useState } from 'react'; import React, { useCallback, useEffect, useRef, useState } from 'react';
import type { AppItemOverview } from 'types/client/apps'; import type { AppItemOverview } from 'types/client/apps';
import appConfig from 'configs/app/config'; import appConfig from 'configs/app/config';
import link from 'lib/link/link';
import ContentLoader from 'ui/shared/ContentLoader'; import ContentLoader from 'ui/shared/ContentLoader';
import Page from 'ui/shared/Page/Page'; import Page from 'ui/shared/Page/Page';
...@@ -26,9 +26,9 @@ const MarketplaceApp = ({ app, isLoading }: Props) => { ...@@ -26,9 +26,9 @@ const MarketplaceApp = ({ app, isLoading }: Props) => {
if (app && !isFrameLoading) { if (app && !isFrameLoading) {
const message = { const message = {
blockscoutColorMode: colorMode, blockscoutColorMode: colorMode,
blockscoutRootUrl: link('network_index'), blockscoutRootUrl: appConfig.baseUrl + route({ pathname: '/' }),
blockscoutAddressExplorerUrl: link('address_index'), blockscoutAddressExplorerUrl: appConfig.baseUrl + route({ pathname: '/address/[id]', query: { id: '' } }),
blockscoutTransactionExplorerUrl: link('tx'), blockscoutTransactionExplorerUrl: appConfig.baseUrl + route({ pathname: '/tx/[hash]', query: { hash: '' } }),
blockscoutNetworkName: appConfig.network.name, blockscoutNetworkName: appConfig.network.name,
blockscoutNetworkId: Number(appConfig.network.id), blockscoutNetworkId: Number(appConfig.network.id),
blockscoutNetworkCurrency: appConfig.network.currency, blockscoutNetworkCurrency: appConfig.network.currency,
......
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