updated event controllers and service event mtach tested
This commit is contained in:
@@ -33,6 +33,6 @@ export default async function ProtectedLayout({
|
||||
const headersList = await headers();
|
||||
// const locale = getLocaleFromPath(removeSubStringFromPath(headersList));
|
||||
const removedLocaleRoute = removeSubStringFromPath(headersList);
|
||||
console.log('Removed locale route:', removedLocaleRoute);
|
||||
// console.log('Removed locale route:', removedLocaleRoute);
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
'use server';
|
||||
import React from 'react';
|
||||
import { dashboardPages } from '@/pages/office/dashboard/mapper';
|
||||
import { renderPage } from '@/lib/page';
|
||||
import { getSelectToken } from '@/fetchers/token/select';
|
||||
|
||||
|
||||
export default async function DashboardPage() {
|
||||
const pageUrl = "/office/dashboard";
|
||||
const selectToken = await getSelectToken();
|
||||
const RenderPage = renderPage(selectToken, pageUrl, dashboardPages);
|
||||
if (RenderPage) {
|
||||
|
||||
return <>
|
||||
<div>Dashboard Page</div>
|
||||
<div className='flex align-center justify-center h-screen w-screen mt-10 text-2xl'>
|
||||
<RenderPage />
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
return <>
|
||||
<div>Dashboard Page</div>
|
||||
<div>You are not allowed to reach any page under {pageUrl}. Please contact your administrator.</div>
|
||||
</>;
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
'use server';
|
||||
import React from 'react';
|
||||
import { dashboardPages } from '@/pages/venue/dashboard/mapper';
|
||||
import { renderPage } from '@/lib/page';
|
||||
import { getSelectTokenObject } from '@/fetchers/token/select';
|
||||
|
||||
export default async function DashboardPage() {
|
||||
const pageUrl = "/venue/dashboard";
|
||||
const selectToken = await getSelectTokenObject();
|
||||
if (!selectToken) {
|
||||
const RenderPage = renderPage(selectToken, pageUrl, dashboardPages);
|
||||
if (RenderPage) {
|
||||
return <>
|
||||
<div>Dashboard Page</div>
|
||||
<div className='flex align-center justify-center h-screen w-screen mt-10 text-2xl'>
|
||||
<RenderPage />
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
}
|
||||
return <>
|
||||
<div>Dashboard Page</div>
|
||||
<div>You are not allowed to reach any page under {pageUrl}. Please contact your administrator.</div>
|
||||
</>;
|
||||
};
|
||||
@@ -32,6 +32,7 @@ interface UpdateFieldParams<T> {
|
||||
}
|
||||
|
||||
type RScan = Promise<string | null>;
|
||||
type RScanToken = Promise<any | null>;
|
||||
type RExists = Promise<boolean>;
|
||||
type RUpdate = Promise<void>;
|
||||
type RDelete = Promise<void>;
|
||||
@@ -122,3 +123,38 @@ export async function scanByRKeyDouble(params: DScanParams): RScan {
|
||||
} while (cursor !== "0");
|
||||
return keys.length > 0 ? keys[0] : null;
|
||||
}
|
||||
|
||||
export async function scanByRKeySingleToken(params: SScanParams): RScan {
|
||||
const pattern = redisScanAccess(params.rKey);
|
||||
const keys: string[] = [];
|
||||
let cursor = "0";
|
||||
do {
|
||||
const [nextCursor, matchedKeys] = await redis.scan(
|
||||
cursor,
|
||||
"MATCH",
|
||||
pattern
|
||||
);
|
||||
cursor = nextCursor;
|
||||
keys.push(...matchedKeys);
|
||||
} while (cursor !== "0");
|
||||
if (keys.length === 0) return null;
|
||||
return await getJSON({ key: keys[0] });
|
||||
}
|
||||
|
||||
export async function scanByRKeyDoubleToken(params: DScanParams): RScan {
|
||||
const pattern = redisScanSelect(params.rKey, params.sKey);
|
||||
console.log("pattern", pattern);
|
||||
const keys: string[] = [];
|
||||
let cursor = "0";
|
||||
do {
|
||||
const [nextCursor, matchedKeys] = await redis.scan(
|
||||
cursor,
|
||||
"MATCH",
|
||||
pattern
|
||||
);
|
||||
cursor = nextCursor;
|
||||
keys.push(...matchedKeys);
|
||||
} while (cursor !== "0");
|
||||
if (keys.length === 0) return null;
|
||||
return await getJSON({ key: keys[0] });
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use server';
|
||||
import { AuthError } from "@/fetchers/types/base";
|
||||
import { scanByRKeyDouble } from "@/fetchers/redis/redisService";
|
||||
import { scanByRKeyDouble, scanByRKeyDoubleToken, scanByRKeySingleToken } from "@/fetchers/redis/redisService";
|
||||
import { getPlainAccessToken } from "./access";
|
||||
import { nextCrypto } from "@/fetchers/base";
|
||||
import { getCookieSelectToken, removeCookieTokens, setCookieSelectToken } from "./cookies";
|
||||
@@ -54,6 +54,30 @@ async function getSelectToken() {
|
||||
catch (error) { throw new AuthError("No select token found in headers") }
|
||||
}
|
||||
|
||||
async function getSelectTokenObject() {
|
||||
try {
|
||||
const plainAccessToken = await getPlainAccessToken();
|
||||
const plainSelectToken = await getPlainSelectToken();
|
||||
console.log('plainAccessToken', plainAccessToken);
|
||||
console.log('plainSelectToken', plainSelectToken);
|
||||
const scanToken = await scanByRKeyDoubleToken({ rKey: plainAccessToken, sKey: plainSelectToken });
|
||||
if (!scanToken) throw new AuthError("Select token is invalid");
|
||||
return scanToken;
|
||||
}
|
||||
catch (error) { throw new AuthError("No select token found in headers") }
|
||||
}
|
||||
|
||||
async function getAccessTokenObject() {
|
||||
try {
|
||||
const plainAccessToken = await getPlainAccessToken();
|
||||
console.log('plainAccessToken', plainAccessToken);
|
||||
const scanToken = await scanByRKeySingleToken({ rKey: plainAccessToken });
|
||||
if (!scanToken) throw new AuthError("Access token is invalid");
|
||||
return scanToken;
|
||||
}
|
||||
catch (error) { throw new AuthError("No access token found in headers") }
|
||||
}
|
||||
|
||||
async function setSelectToken(token: string) {
|
||||
console.log('setSelectToken is triggered...');
|
||||
await setCookieSelectToken(token);
|
||||
@@ -75,4 +99,4 @@ async function removeSelectToken() {
|
||||
await removeCookieTokens();
|
||||
}
|
||||
|
||||
export { getSelectToken, setSelectToken, removeSelectToken, getPlainSelectToken, isSelectTokenValid };
|
||||
export { getSelectToken, setSelectToken, removeSelectToken, getPlainSelectToken, isSelectTokenValid, getSelectTokenObject, getAccessTokenObject };
|
||||
|
||||
10
ServicesFrontEnd/frontend/src/lib/page.tsx
Normal file
10
ServicesFrontEnd/frontend/src/lib/page.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
function renderPage(selectToken: any, pageUrl: string, dashboardPages: any) {
|
||||
const subPageKey = selectToken.pages[pageUrl];
|
||||
if (Object.keys(dashboardPages).includes(subPageKey)) {
|
||||
const subPage = dashboardPages[subPageKey as keyof typeof dashboardPages];
|
||||
if (subPage) { if (subPage.page) { return subPage.page } }
|
||||
} return null;
|
||||
}
|
||||
|
||||
export { renderPage };
|
||||
@@ -0,0 +1,11 @@
|
||||
'use client';
|
||||
|
||||
const DashboardU0QncONSk22PFxZ5xefmgx: React.FC = () => {
|
||||
return (
|
||||
<div>
|
||||
<h1>DashboardU0QncONSk22PFxZ5xefmgx</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default DashboardU0QncONSk22PFxZ5xefmgx;
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Page } from "@/pages/types/page";
|
||||
import DashboardU0QncONSk22PFxZ5xefmgx from "./U0QncONSk22PFxZ5xefmgx";
|
||||
|
||||
const dashboardPages: Page = {
|
||||
"qY56XMEr08wJkNvOR6EYQZKMVdTQEfHdLXGzzxcKU24E:U0QncONSk22PFxZ5xefmgx": {
|
||||
name: "DashboardU0QncONSk22PFxZ5xefmgx",
|
||||
key: "U0QncONSk22PFxZ5xefmgx",
|
||||
url: "/venue/dashboard",
|
||||
page: DashboardU0QncONSk22PFxZ5xefmgx,
|
||||
description: "Dashboard",
|
||||
isDefault: true,
|
||||
params: {},
|
||||
events: ["Aevent", "Aevent", "Aevent"],
|
||||
tokens: ["TOKEN", "TOKEN", "TOKEN", "TOKEN"]
|
||||
}
|
||||
};
|
||||
|
||||
export { dashboardPages };
|
||||
14
ServicesFrontEnd/frontend/src/pages/types/page.ts
Normal file
14
ServicesFrontEnd/frontend/src/pages/types/page.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export interface Page {
|
||||
[key: string]: {
|
||||
name: string;
|
||||
key: string;
|
||||
url: string;
|
||||
page: React.FC;
|
||||
description: string;
|
||||
isDefault: boolean;
|
||||
params: Record<string, boolean>;
|
||||
events?: string[];
|
||||
tokens?: string[];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
'use client';
|
||||
|
||||
const DashboardIdTch3qS9aJXkvqXodAxxx: React.FC = () => {
|
||||
return (
|
||||
<div>
|
||||
<h1>DashboardIdTch3qS9aJXkvqXodAxxx</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default DashboardIdTch3qS9aJXkvqXodAxxx;
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Page } from "@/pages/types/page";
|
||||
import DashboardIdTch3qS9aJXkvqXodAxxx from "./IdTch3qS9aJXkvqXodAxxx";
|
||||
|
||||
const dashboardPages: Page = {
|
||||
"IbGpchaw3muiY7y9rnV0EJYoPy5XoOOrITT9JlfIbqwE:IdTch3qS9aJXkvqXodAxxx": {
|
||||
name: "DashboardIdTch3qS9aJXkvqXodAxxx",
|
||||
key: "IdTch3qS9aJXkvqXodAxxx",
|
||||
url: "/venue/dashboard",
|
||||
page: DashboardIdTch3qS9aJXkvqXodAxxx,
|
||||
description: "Dashboard",
|
||||
isDefault: true,
|
||||
params: {},
|
||||
events: ["Aevent", "Aevent", "Aevent"],
|
||||
tokens: ["TOKEN", "TOKEN", "TOKEN", "TOKEN"]
|
||||
}
|
||||
};
|
||||
|
||||
export { dashboardPages };
|
||||
Reference in New Issue
Block a user