Skip to content

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

feat: update auth sign in report query (#37240)

Cemal Kılıç09fc7776b5cb
diff --git a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx b/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
index d7151ff115b..14161b06fd3 100644
--- a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
+++ b/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
@@ -55,6 +55,7 @@ export type MultiAttribute = {
omitFromTotal?: boolean
tooltip?: string
customValue?: number
+ [key: string]: any
/**
* Manipulate the value of the attribute before it is displayed on the chart.
* @param value - The value of the attribute.
diff --git a/apps/studio/data/reports/auth-charts.ts b/apps/studio/data/reports/auth-charts.ts
index 27965738927..14676a0b23c 100644
--- a/apps/studio/data/reports/auth-charts.ts
+++ b/apps/studio/data/reports/auth-charts.ts
@@ -29,28 +29,28 @@ export const getAuthReportAttributes = (isFreePlan: boolean) => [
attribute: 'SignInAttempts',
provider: 'logs',
label: 'Password',
- grantType: 'password',
+ login_type_provider: 'password',
enabled: true,
},
{
attribute: 'SignInAttempts',
provider: 'logs',
label: 'PKCE',
- grantType: 'pkce',
+ login_type_provider: 'pkce',
enabled: true,
},
{
attribute: 'SignInAttempts',
provider: 'logs',
label: 'Refresh Token',
- grantType: 'refresh_token',
+ login_type_provider: 'token',
enabled: true,
},
{
attribute: 'SignInAttempts',
provider: 'logs',
label: 'ID Token',
- grantType: 'id_token',
+ login_type_provider: 'id_token',
enabled: true,
},
],
diff --git a/apps/studio/data/reports/auth-report-query.ts b/apps/studio/data/reports/auth-report-query.ts
index 99f6ec0c352..f1d7f7cfd87 100644
--- a/apps/studio/data/reports/auth-report-query.ts
+++ b/apps/studio/data/reports/auth-report-query.ts
@@ -64,14 +64,29 @@ const METRIC_SQL: Record<MetricKey, (interval: AnalyticsInterval) => string> = {
const granularity = analyticsIntervalToGranularity(interval)
return `
--sign-in-attempts
- select
+ SELECT
timestamp_trunc(timestamp, ${granularity}) as timestamp,
- json_value(event_message, "$.grant_type") as grant_type,
- count(*) as count
- from auth_logs
- where json_value(event_message, "$.path") = '/token'
- group by timestamp, grant_type
- order by timestamp desc, grant_type
+ CASE
+ WHEN JSON_VALUE(event_message, "$.provider") IS NOT NULL
+ AND JSON_VALUE(event_message, "$.provider") != ''
+ THEN CONCAT(
+ JSON_VALUE(event_message, "$.login_method"),
+ ' (',
+ JSON_VALUE(event_message, "$.provider"),
+ ')'
+ )
+ ELSE JSON_VALUE(event_message, "$.login_method")
+ END as login_type_provider,
+ COUNT(*) as count
+ FROM
+ auth_logs
+ WHERE
+ JSON_VALUE(event_message, "$.action") = 'login'
+ AND JSON_VALUE(event_message, "$.metering") = "true"
+ GROUP BY
+ timestamp, login_type_provider
+ ORDER BY
+ timestamp desc, login_type_provider
`
},
PasswordResetRequests: (interval) => {
@@ -196,8 +211,8 @@ const METRIC_FORMATTER: Record<
ActiveUsers: (rawData, attributes) => defaultFormatter(rawData, attributes),
SignInAttempts: (rawData, attributes) => {
const chartAttributes = attributes.map((attr) => {
- if (attr.attribute === 'SignInAttempts' && attr.grantType) {
- return { ...attr, attribute: `${attr.attribute}_${attr.grantType}` }
+ if (attr.attribute === 'SignInAttempts' && attr.login_type_provider) {
+ return { ...attr, attribute: `${attr.attribute}_${attr.login_type_provider}` }
}
return attr
})
@@ -213,7 +228,7 @@ const METRIC_FORMATTER: Record<
})
const matchingPoints = result.filter((p: any) => p.timestamp === timestamp)
matchingPoints.forEach((p: any) => {
- point[`SignInAttempts_${p.grant_type}`] = p.count
+ point[`SignInAttempts_${p.login_type_provider}`] = p.count
})
return point
})