Skip to content

Commit 09fc777

Browse files
cemalkilicjordienr
andauthored
feat: update auth sign in report query (supabase#37240)
* feat: update auth sign in report query * fix chart config * fix type error for custom properties in chart attributes --------- Co-authored-by: Jordi Enric <[email protected]>
1 parent eb01061 commit 09fc777

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

apps/studio/components/ui/Charts/ComposedChart.utils.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export type MultiAttribute = {
5555
omitFromTotal?: boolean
5656
tooltip?: string
5757
customValue?: number
58+
[key: string]: any
5859
/**
5960
* Manipulate the value of the attribute before it is displayed on the chart.
6061
* @param value - The value of the attribute.

apps/studio/data/reports/auth-charts.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,28 @@ export const getAuthReportAttributes = (isFreePlan: boolean) => [
2929
attribute: 'SignInAttempts',
3030
provider: 'logs',
3131
label: 'Password',
32-
grantType: 'password',
32+
login_type_provider: 'password',
3333
enabled: true,
3434
},
3535
{
3636
attribute: 'SignInAttempts',
3737
provider: 'logs',
3838
label: 'PKCE',
39-
grantType: 'pkce',
39+
login_type_provider: 'pkce',
4040
enabled: true,
4141
},
4242
{
4343
attribute: 'SignInAttempts',
4444
provider: 'logs',
4545
label: 'Refresh Token',
46-
grantType: 'refresh_token',
46+
login_type_provider: 'token',
4747
enabled: true,
4848
},
4949
{
5050
attribute: 'SignInAttempts',
5151
provider: 'logs',
5252
label: 'ID Token',
53-
grantType: 'id_token',
53+
login_type_provider: 'id_token',
5454
enabled: true,
5555
},
5656
],

apps/studio/data/reports/auth-report-query.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,29 @@ const METRIC_SQL: Record<MetricKey, (interval: AnalyticsInterval) => string> = {
6464
const granularity = analyticsIntervalToGranularity(interval)
6565
return `
6666
--sign-in-attempts
67-
select
67+
SELECT
6868
timestamp_trunc(timestamp, ${granularity}) as timestamp,
69-
json_value(event_message, "$.grant_type") as grant_type,
70-
count(*) as count
71-
from auth_logs
72-
where json_value(event_message, "$.path") = '/token'
73-
group by timestamp, grant_type
74-
order by timestamp desc, grant_type
69+
CASE
70+
WHEN JSON_VALUE(event_message, "$.provider") IS NOT NULL
71+
AND JSON_VALUE(event_message, "$.provider") != ''
72+
THEN CONCAT(
73+
JSON_VALUE(event_message, "$.login_method"),
74+
' (',
75+
JSON_VALUE(event_message, "$.provider"),
76+
')'
77+
)
78+
ELSE JSON_VALUE(event_message, "$.login_method")
79+
END as login_type_provider,
80+
COUNT(*) as count
81+
FROM
82+
auth_logs
83+
WHERE
84+
JSON_VALUE(event_message, "$.action") = 'login'
85+
AND JSON_VALUE(event_message, "$.metering") = "true"
86+
GROUP BY
87+
timestamp, login_type_provider
88+
ORDER BY
89+
timestamp desc, login_type_provider
7590
`
7691
},
7792
PasswordResetRequests: (interval) => {
@@ -196,8 +211,8 @@ const METRIC_FORMATTER: Record<
196211
ActiveUsers: (rawData, attributes) => defaultFormatter(rawData, attributes),
197212
SignInAttempts: (rawData, attributes) => {
198213
const chartAttributes = attributes.map((attr) => {
199-
if (attr.attribute === 'SignInAttempts' && attr.grantType) {
200-
return { ...attr, attribute: `${attr.attribute}_${attr.grantType}` }
214+
if (attr.attribute === 'SignInAttempts' && attr.login_type_provider) {
215+
return { ...attr, attribute: `${attr.attribute}_${attr.login_type_provider}` }
201216
}
202217
return attr
203218
})
@@ -213,7 +228,7 @@ const METRIC_FORMATTER: Record<
213228
})
214229
const matchingPoints = result.filter((p: any) => p.timestamp === timestamp)
215230
matchingPoints.forEach((p: any) => {
216-
point[`SignInAttempts_${p.grant_type}`] = p.count
231+
point[`SignInAttempts_${p.login_type_provider}`] = p.count
217232
})
218233
return point
219234
})

0 commit comments

Comments
 (0)