fix undefined share params allowing access to pages
This commit is contained in:
@@ -27,6 +27,7 @@ const ALL_SECTION_IDS = [
|
||||
'events',
|
||||
'sessions',
|
||||
'realtime',
|
||||
'performance',
|
||||
'compare',
|
||||
'breakdown',
|
||||
'goals',
|
||||
@@ -59,7 +60,7 @@ export function ShareProvider({ slug, children }: { slug: string; children: Reac
|
||||
const isWebsiteShare = share?.shareType === ENTITY_TYPE.website;
|
||||
|
||||
const allowedSections = isWebsiteShare && share?.parameters
|
||||
? ALL_SECTION_IDS.filter(id => share.parameters[id] !== false)
|
||||
? ALL_SECTION_IDS.filter(id => share.parameters[id] === true)
|
||||
: [];
|
||||
|
||||
const shouldRedirect = isWebsiteShare &&
|
||||
|
||||
@@ -23,7 +23,7 @@ import { useShare } from '@/components/hooks';
|
||||
import { MobileMenuButton } from '@/components/input/MobileMenuButton';
|
||||
import { ENTITY_TYPE } from '@/lib/constants';
|
||||
import { Column, Grid, Row, useTheme } from '@umami/react-zen';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { ShareFooter } from './ShareFooter';
|
||||
import { ShareNav } from './ShareNav';
|
||||
@@ -69,9 +69,10 @@ export function SharePage() {
|
||||
};
|
||||
const share = useShare();
|
||||
const { setTheme } = useTheme();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const path = getSharePath(pathname);
|
||||
const { websiteId, boardId, pixelId, linkId, parameters = {}, shareType } = share;
|
||||
const { slug, websiteId, boardId, pixelId, linkId, parameters = {}, shareType } = share;
|
||||
|
||||
useEffect(() => {
|
||||
const url = new URL(window?.location?.href);
|
||||
@@ -102,9 +103,10 @@ export function SharePage() {
|
||||
|
||||
// Check if the requested path is allowed
|
||||
const pageKey = path || '';
|
||||
const isAllowed = pageKey === '' || pageKey === 'overview' || parameters[pageKey] !== false;
|
||||
const isAllowed = pageKey === '' || parameters[pageKey] === true;
|
||||
|
||||
if (!isAllowed) {
|
||||
router.replace(`/share/${slug}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user