Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: add banned user widget and unverified users widget

TzeYiing4ac96293a02b
diff --git a/studio/components/interfaces/Reports/Reports.constants.ts b/studio/components/interfaces/Reports/Reports.constants.ts
index 187bb9a7543..e76f48949ac 100644
--- a/studio/components/interfaces/Reports/Reports.constants.ts
+++ b/studio/components/interfaces/Reports/Reports.constants.ts
@@ -162,6 +162,28 @@ export const PRESET_CONFIG: Record<Presets, PresetConfig> = {
[Presets.AUTH]: {
title: 'Auth',
queries: {
+ bannedUsers: {
+ queryType: "db",
+ sql: `
+select
+ count(distinct u.id) as count
+from auth.users u
+where u.banned_until is not null and u.banned_until > now()
+limit 1
+ `
+ },
+ unverifiedUsers: {
+ queryType: "db",
+ sql: `
+select
+ date_trunc('day', u.created_at) as timestamp,
+ count(distinct u.id) as count
+from auth.users u
+where u.confirmed_at is null
+group by timestamp
+order by timestamp desc
+ `
+ },
signUpProviders: {
queryType: "db",
sql: `
@@ -207,6 +229,7 @@ select
date_trunc('day', u.created_at) as timestamp,
sum(count(u.id)) over (order by date_trunc('day', u.created_at)) as count
from auth.users as u
+where u.confirmed_at is not null
group by timestamp
order by timestamp desc
`,
diff --git a/studio/components/interfaces/Reports/Statistic.tsx b/studio/components/interfaces/Reports/Statistic.tsx
index 9f21c6feefc..61c26979c05 100644
--- a/studio/components/interfaces/Reports/Statistic.tsx
+++ b/studio/components/interfaces/Reports/Statistic.tsx
@@ -1,3 +1,4 @@
+import Sparkline from 'components/ui/Charts/Sparkline'
import React from 'react'
interface Props {
@@ -6,12 +7,24 @@ interface Props {
prefix?: string
suffix?: string
valueFormatter?: (value: Props['value']) => string
+ sparklineData?: Record<string, number>[]
+ sparklineXAxis?: string
+ sparklineYAxis?: string
}
-const Statistic: React.FC<Props> = ({ prefix, suffix, value, startingValue }) => {
+const Statistic: React.FC<Props> = ({
+ prefix,
+ suffix,
+ value,
+ startingValue,
+ sparklineData,
+ sparklineXAxis,
+ sparklineYAxis,
+}) => {
const isNumber = typeof value === 'number' && !Number.isNaN(value)
const percentageChange =
startingValue && isNumber ? Number(startingValue) / Number(value) - 1 : null
+ const showSparkline = sparklineData && sparklineXAxis && sparklineYAxis
return (
<div className="w-full">
<div className="flex flex-row justify-center">
@@ -29,6 +42,9 @@ const Statistic: React.FC<Props> = ({ prefix, suffix, value, startingValue }) =>
)}
</div>
)}
+ {showSparkline && (
+ <Sparkline data={sparklineData} xAxisKey={sparklineXAxis} yAxisKey={sparklineYAxis} />
+ )}
</div>
)
}
diff --git a/studio/components/interfaces/Reports/renderers/AuthRenderers.tsx b/studio/components/interfaces/Reports/renderers/AuthRenderers.tsx
index f69dcc88e10..fbd38fb6c5f 100644
--- a/studio/components/interfaces/Reports/renderers/AuthRenderers.tsx
+++ b/studio/components/interfaces/Reports/renderers/AuthRenderers.tsx
@@ -4,6 +4,23 @@ import { DATETIME_FORMAT } from '../Reports.constants'
import { ReportWidgetProps } from '../ReportWidget'
import Statistic from '../Statistic'
+export const renderBannedUsers = (
+ props: ReportWidgetProps<{
+ count: number
+ }>
+) => {
+ const count = props.data.length === 0 ? 0 : props?.data?.[0]?.count
+ return <Statistic value={count} />
+}
+export const renderUnverifiedUsers = (
+ props: ReportWidgetProps<{
+ timestamp: string
+ count: number
+ }>
+) => {
+ const count = props.data.length === 0 ? 0 : props?.data?.[0]?.count
+ return <Statistic value={count} />
+}
export const renderSignUpProviders = (
props: ReportWidgetProps<{
timestamp: string
diff --git a/studio/components/ui/Charts/StackedBarChart.tsx b/studio/components/ui/Charts/StackedBarChart.tsx
index df9f6484ce3..d378cef19a8 100644
--- a/studio/components/ui/Charts/StackedBarChart.tsx
+++ b/studio/components/ui/Charts/StackedBarChart.tsx
@@ -43,7 +43,7 @@ const StackedBarChart: React.FC<Props> = ({
variant,
})
const [focusDataIndex, setFocusDataIndex] = useState<number | null>(null)
- if (data.length === 0) return <NoDataPlaceholder />
+ if (!data || data.length === 0) return <NoDataPlaceholder />
return (
<div className="w-full">
{!hideHeader && (
diff --git a/studio/pages/project/[ref]/reports/auth.tsx b/studio/pages/project/[ref]/reports/auth.tsx
index 0d84ed91ebe..d57839ebf23 100644
--- a/studio/pages/project/[ref]/reports/auth.tsx
+++ b/studio/pages/project/[ref]/reports/auth.tsx
@@ -13,6 +13,8 @@ import {
renderCumulativeUsers,
renderFailedMigrations,
renderSignUpProviders,
+ renderUnverifiedUsers,
+ renderBannedUsers,
} from 'components/interfaces/Reports/renderers/AuthRenderers'
export const AuthReport: NextPageWithLayout = () => {
@@ -25,6 +27,8 @@ export const AuthReport: NextPageWithLayout = () => {
const cumulativeUsers = hooks.cumulativeUsers()
const failedMigrations = hooks.failedMigrations()
const signUpProviders = hooks.signUpProviders()
+ const unverifiedUsers = hooks.unverifiedUsers()
+ const bannedUsers = hooks.bannedUsers()
const { isLoading, Layout } = usePresetReport([
dailyActiveUsers,
@@ -32,10 +36,11 @@ export const AuthReport: NextPageWithLayout = () => {
cumulativeUsers,
failedMigrations,
signUpProviders,
+ unverifiedUsers,
])
return (
<Layout title={config.title}>
- <div className="grid lg:grid-cols-6 gap-4">
+ <div className="flex flex-col grid lg:grid-cols-6 gap-4">
<h2>User Activity</h2>
<ReportWidget
@@ -69,13 +74,33 @@ export const AuthReport: NextPageWithLayout = () => {
<ReportWidget
isLoading={isLoading}
params={signUpProviders[0].params}
- className="col-span-6 col-start-1"
+ className="row-span-4 col-span-4 col-start-3"
title="Sign Up Providers"
description="The breakdown of providers used for user creation"
data={signUpProviders[0].data!}
renderer={renderSignUpProviders}
/>
- <h2>Sever Health</h2>
+ <ReportWidget
+ isLoading={isLoading}
+ params={unverifiedUsers[0].params}
+ className="row-span-1 col-span-2 col-start-1"
+ title="Unverified Users"
+ tooltip="High number of unverified users may indicate spamming and malicious behavior."
+ data={unverifiedUsers[0].data! || []}
+ renderer={renderUnverifiedUsers}
+ />
+
+ <ReportWidget
+ isLoading={isLoading}
+ params={bannedUsers[0].params}
+ className="row-span-1 col-span-2 col-start-1"
+ title="Banned Users"
+ tooltip="High number of banned users may indicate malicious behavior."
+ data={bannedUsers[0].data! || []}
+ renderer={renderBannedUsers}
+ />
+
+ <h2 className="col-span-full">Sever Health</h2>
<ReportWidget
isLoading={isLoading}
params={failedMigrations[0].params}