Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix(dashboard): shared pages no longer send visitors to the login page

Carl-Gerhard Lindesvärd505fd731e48a
diff --git a/apps/start/src/components/overview/overview-top-devices.tsx b/apps/start/src/components/overview/overview-top-devices.tsx
index ed56c4574..eeb09c01f 100644
--- a/apps/start/src/components/overview/overview-top-devices.tsx
+++ b/apps/start/src/components/overview/overview-top-devices.tsx
@@ -424,6 +424,7 @@ export default function OverviewTopDevices({
onClick={() =>
pushModal('OverviewTopGenericModal', {
projectId,
+ shareId,
column: widget.key,
})
}
diff --git a/apps/start/src/components/overview/overview-top-generic-modal.tsx b/apps/start/src/components/overview/overview-top-generic-modal.tsx
index 65e15c5fd..b499bc45e 100644
--- a/apps/start/src/components/overview/overview-top-generic-modal.tsx
+++ b/apps/start/src/components/overview/overview-top-generic-modal.tsx
@@ -13,11 +13,13 @@ import { useTRPC } from '@/integrations/trpc/react';
interface OverviewTopGenericModalProps {
projectId: string;
+ shareId?: string;
column: IGetTopGenericInput['column'];
}
export default function OverviewTopGenericModal({
projectId,
+ shareId,
column,
}: OverviewTopGenericModalProps) {
const [_filters, setFilter] = useEventQueryFilters();
@@ -26,6 +28,7 @@ export default function OverviewTopGenericModal({
const query = useQuery(
trpc.overview.topGeneric.queryOptions({
projectId,
+ shareId,
filters: _filters,
startDate,
endDate,
diff --git a/apps/start/src/components/overview/overview-top-geo.tsx b/apps/start/src/components/overview/overview-top-geo.tsx
index c18b0b74c..5e6bc66b2 100644
--- a/apps/start/src/components/overview/overview-top-geo.tsx
+++ b/apps/start/src/components/overview/overview-top-geo.tsx
@@ -191,6 +191,7 @@ export default function OverviewTopGeo({
onClick={() =>
pushModal('OverviewTopGenericModal', {
projectId,
+ shareId,
column: widget.key,
})
}
diff --git a/apps/start/src/components/overview/overview-top-pages-modal.tsx b/apps/start/src/components/overview/overview-top-pages-modal.tsx
index 08424150f..11a40ab21 100644
--- a/apps/start/src/components/overview/overview-top-pages-modal.tsx
+++ b/apps/start/src/components/overview/overview-top-pages-modal.tsx
@@ -9,10 +9,12 @@ import { useTRPC } from '@/integrations/trpc/react';
interface OverviewTopPagesProps {
projectId: string;
+ shareId?: string;
}
export default function OverviewTopPagesModal({
projectId,
+ shareId,
}: OverviewTopPagesProps) {
const [filters, setFilter] = useEventQueryFilters();
const { startDate, endDate, range } = useOverviewOptions();
@@ -20,6 +22,7 @@ export default function OverviewTopPagesModal({
const query = useQuery(
trpc.overview.topPages.queryOptions({
projectId,
+ shareId,
filters,
startDate,
endDate,
diff --git a/apps/start/src/components/overview/overview-top-pages.tsx b/apps/start/src/components/overview/overview-top-pages.tsx
index 690f563c0..e60f2ec1d 100644
--- a/apps/start/src/components/overview/overview-top-pages.tsx
+++ b/apps/start/src/components/overview/overview-top-pages.tsx
@@ -120,7 +120,9 @@ export default function OverviewTopPages({
</WidgetBody>
<WidgetFooter>
<OverviewDetailsButton
- onClick={() => pushModal('OverviewTopPagesModal', { projectId })}
+ onClick={() =>
+ pushModal('OverviewTopPagesModal', { projectId, shareId })
+ }
/>
<div className="flex-1" />
<Button
diff --git a/apps/start/src/components/overview/overview-top-sources.tsx b/apps/start/src/components/overview/overview-top-sources.tsx
index 4d53d00ae..a5fa73476 100644
--- a/apps/start/src/components/overview/overview-top-sources.tsx
+++ b/apps/start/src/components/overview/overview-top-sources.tsx
@@ -180,6 +180,7 @@ export default function OverviewTopSources({
onClick={() =>
pushModal('OverviewTopGenericModal', {
projectId,
+ shareId,
column: widget.key,
})
}
diff --git a/apps/start/src/components/report-chart/area/chart.tsx b/apps/start/src/components/report-chart/area/chart.tsx
index 3fe4db4c6..61a61ce91 100644
--- a/apps/start/src/components/report-chart/area/chart.tsx
+++ b/apps/start/src/components/report-chart/area/chart.tsx
@@ -56,6 +56,7 @@ export function Chart({ data }: Props) {
visibleSeries: savedVisibleSeries,
},
isEditMode,
+ shareId,
options: { hideXAxis, hideYAxis },
} = useReportChartContext();
const dispatch = useDispatch();
@@ -140,7 +141,8 @@ export function Chart({ data }: Props) {
(e: any, clickedData: any): ChartClickMenuItem[] => {
const items: ChartClickMenuItem[] = [];
- if (!clickedData?.date) {
+ // Both actions need a signed-in member, which a share visitor is not.
+ if (shareId || !clickedData?.date) {
return items;
}
@@ -185,6 +187,7 @@ export function Chart({ data }: Props) {
return items;
},
[
+ shareId,
projectId,
data,
reportSeries,
diff --git a/apps/start/src/components/report-chart/common/chart-click-menu.tsx b/apps/start/src/components/report-chart/common/chart-click-menu.tsx
index abe7210ea..6ee59b58c 100644
--- a/apps/start/src/components/report-chart/common/chart-click-menu.tsx
+++ b/apps/start/src/components/report-chart/common/chart-click-menu.tsx
@@ -207,7 +207,7 @@ export const ChartClickMenu = forwardRef<
<div className="relative h-full w-full" ref={containerRef}>
<DropdownMenu
onOpenChange={handleOpenChange}
- open={clickPosition !== null}
+ open={clickPosition !== null && menuItems.length > 0}
>
<DropdownMenuTrigger asChild>
<div
diff --git a/apps/start/src/components/report-chart/conversion/chart.tsx b/apps/start/src/components/report-chart/conversion/chart.tsx
index b6befc406..0562c64be 100644
--- a/apps/start/src/components/report-chart/conversion/chart.tsx
+++ b/apps/start/src/components/report-chart/conversion/chart.tsx
@@ -52,6 +52,7 @@ export function Chart({ data }: Props) {
visibleSeries: savedVisibleSeries,
},
isEditMode,
+ shareId,
options: { hideXAxis, hideYAxis, maxDomain },
} = useReportChartContext();
const dispatch = useDispatch();
@@ -157,7 +158,10 @@ export function Chart({ data }: Props) {
>
<div className={cn('h-full w-full', isEditMode && 'card p-4')}>
<ResponsiveContainer>
- <LineChart data={rechartData} onClick={handleChartClick}>
+ <LineChart
+ data={rechartData}
+ onClick={shareId ? undefined : handleChartClick}
+ >
<CartesianGrid
className="stroke-border"
horizontal={true}
diff --git a/apps/start/src/components/report-chart/funnel/chart.tsx b/apps/start/src/components/report-chart/funnel/chart.tsx
index 82deef418..1dec1d9c4 100644
--- a/apps/start/src/components/report-chart/funnel/chart.tsx
+++ b/apps/start/src/components/report-chart/funnel/chart.tsx
@@ -140,6 +140,7 @@ export function Tables({
previous,
options,
},
+ shareId,
} = useReportChartContext();
const funnelOptions = options?.type === 'funnel' ? options : undefined;
@@ -282,23 +283,24 @@ export function Tables({
},
{
name: '',
- render: (item) => (
- <Button
- className="h-8 w-8 p-0"
- onClick={(e) => {
- e.stopPropagation();
- const stepIndex = steps.findIndex(
- (s) => s.event.id === item.event.id
- );
- handleInspectStep(item, stepIndex);
- }}
- size="sm"
- title="View users who completed this step"
- variant="ghost"
- >
- <UsersIcon size={16} />
- </Button>
- ),
+ render: (item) =>
+ shareId ? null : (
+ <Button
+ className="h-8 w-8 p-0"
+ onClick={(e) => {
+ e.stopPropagation();
+ const stepIndex = steps.findIndex(
+ (s) => s.event.id === item.event.id
+ );
+ handleInspectStep(item, stepIndex);
+ }}
+ size="sm"
+ title="View users who completed this step"
+ variant="ghost"
+ >
+ <UsersIcon size={16} />
+ </Button>
+ ),
className: 'text-right',
width: '48px',
},
diff --git a/apps/start/src/components/report-chart/histogram/chart.tsx b/apps/start/src/components/report-chart/histogram/chart.tsx
index 13eaeaf8d..7582cbc13 100644
--- a/apps/start/src/components/report-chart/histogram/chart.tsx
+++ b/apps/start/src/components/report-chart/histogram/chart.tsx
@@ -53,6 +53,7 @@ function BarHover({ x, y, width, height, top, left, right, bottom }: any) {
export function Chart({ data }: Props) {
const {
isEditMode,
+ shareId,
report: {
previous,
interval,
@@ -100,7 +101,8 @@ export function Chart({ data }: Props) {
(e: any, clickedData: any): ChartClickMenuItem[] => {
const items: ChartClickMenuItem[] = [];
- if (!clickedData?.date) {
+ // Both actions need a signed-in member, which a share visitor is not.
+ if (shareId || !clickedData?.date) {
return items;
}
@@ -145,6 +147,7 @@ export function Chart({ data }: Props) {
return items;
},
[
+ shareId,
projectId,
data,
reportSeries,
diff --git a/apps/start/src/components/report-chart/line/chart.tsx b/apps/start/src/components/report-chart/line/chart.tsx
index 9064e10b1..43197cd44 100644
--- a/apps/start/src/components/report-chart/line/chart.tsx
+++ b/apps/start/src/components/report-chart/line/chart.tsx
@@ -55,6 +55,7 @@ export function Chart({ data }: Props) {
visibleSeries: savedVisibleSeries,
},
isEditMode,
+ shareId,
options: { hideXAxis, hideYAxis, maxDomain },
} = useReportChartContext();
const dispatch = useDispatch();
@@ -142,7 +143,8 @@ export function Chart({ data }: Props) {
(e: any, clickedData: any): ChartClickMenuItem[] => {
const items: ChartClickMenuItem[] = [];
- if (!clickedData?.date) {
+ // Both actions need a signed-in member, which a share visitor is not.
+ if (shareId || !clickedData?.date) {
return items;
}
@@ -198,6 +200,7 @@ export function Chart({ data }: Props) {
return items;
},
[
+ shareId,
projectId,
data,
reportSeries,
diff --git a/apps/start/src/components/report-chart/sankey/index.tsx b/apps/start/src/components/report-chart/sankey/index.tsx
index d323d831c..308eff865 100644
--- a/apps/start/src/components/report-chart/sankey/index.tsx
+++ b/apps/start/src/components/report-chart/sankey/index.tsx
@@ -19,8 +19,10 @@ export function ReportSankeyChart() {
startDate,
endDate,
breakdowns,
+ id,
},
isLazyLoading,
+ shareId,
} = useReportChartContext();
const input: IReportInput = {
@@ -40,9 +42,12 @@ export function ReportSankeyChart() {
};
const trpc = useTRPC();
const res = useQuery(
- trpc.chart.sankey.queryOptions(input, {
- enabled: !isLazyLoading && !!options && input.series.length > 0,
- })
+ trpc.chart.sankey.queryOptions(
+ { ...input, id, shareId },
+ {
+ enabled: !isLazyLoading && !!options && input.series.length > 0,
+ }
+ )
);
if (!options) {
diff --git a/packages/core/src/modules/chart/chart.rpc.ts b/packages/core/src/modules/chart/chart.rpc.ts
index 45f154374..8907da097 100644
--- a/packages/core/src/modules/chart/chart.rpc.ts
+++ b/packages/core/src/modules/chart/chart.rpc.ts
@@ -1,7 +1,7 @@
-// The seven member-only procedures use `protectedProcedure`, so
+// The six member-only procedures use `protectedProcedure`, so
// `enforceAccess` reads the top-level `projectId` before the input is parsed.
//
-// `chartProcedure` (funnel, conversion, chart, aggregate, cohort) is the
+// `chartProcedure` (funnel, conversion, sankey, chart, aggregate, cohort) is the
// share-aware builder: `publicProcedure` plus one middleware that admits an
// anonymous caller holding a valid share — `shareId` + `id` resolve the saved
// report, and the request renders that report (the caller may only move the
@@ -15,7 +15,11 @@ import {
publicProcedure,
type TrpcContext,
} from '../../rpc/base';
-import { TRPCAccessError, TRPCForbiddenError } from '../../rpc/errors';
+import {
+ TRPCBadRequestError,
+ TRPCForbiddenError,
+ TRPCNotFoundError,
+} from '../../rpc/errors';
import {
zChartEventFilter,
zChartSeries,
@@ -50,7 +54,7 @@ async function resolveShare(
return null;
}
if (!input.id) {
- throw new Error('reportId required with shareId');
+ throw new TRPCBadRequestError('reportId required with shareId');
}
const shareValidation = await ctx.services.share.validateShareAccess(
@@ -67,7 +71,7 @@ async function resolveShare(
const report = await ctx.services.report.getReportById(input.id);
if (!report) {
- throw new TRPCAccessError('Report not found');
+ throw new TRPCNotFoundError('Report not found');
}
return report;
}
@@ -155,16 +159,13 @@ export const chartRouter = createTRPCRouter({
)
),
- sankey: protectedProcedure
- .input(zReportInput)
- .query(async ({ input, ctx }) => {
- await ctx.services.auth.requireProjectAccess({
- userId: ctx.session.userId,
- projectId: input.projectId,
- level: 'read',
- });
- return ctx.services.chart.getSankeyChart(input);
- }),
+ sankey: chartProcedure
+ .input(zShareableReportInput)
+ .query(({ input, ctx }) =>
+ ctx.services.chart.getSankeyChart(
+ ctx.services.chart.resolveReportInput(ctx.report, input)
+ )
+ ),
chart: chartProcedure
.input(zShareableReportInput)