Skip to content

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

temp: added flag to hide last used (#41204)

Ali Waseem6f33a251f1a5
diff --git a/apps/studio/components/interfaces/APIKeys/APIKeyRow.tsx b/apps/studio/components/interfaces/APIKeys/APIKeyRow.tsx
index cce0d94e439..c9474f31b42 100644
--- a/apps/studio/components/interfaces/APIKeys/APIKeyRow.tsx
+++ b/apps/studio/components/interfaces/APIKeys/APIKeyRow.tsx
@@ -14,6 +14,7 @@ import {
import { ShimmeringLoader, TimestampInfo } from 'ui-patterns'
import { APIKeyDeleteDialog } from './APIKeyDeleteDialog'
import { ApiKeyPill } from './ApiKeyPill'
+import { useFlag } from 'common'
export const APIKeyRow = ({
apiKey,
@@ -34,6 +35,8 @@ export const APIKeyRow = ({
}) => {
const MotionTableRow = motion.create(TableRow)
+ const hideApiKeyLastUsed = useFlag('HideApiKeyLastUsed')
+
return (
<>
<MotionTableRow
@@ -62,21 +65,23 @@ export const APIKeyRow = ({
</div>
</TableCell>
- <TableCell className="py-2 min-w-0 whitespace-nowrap hidden lg:table-cell">
- <div className="truncate" title={lastSeen?.timestamp.toString() || 'Never used'}>
- {isLoadingLastSeen ? (
- <ShimmeringLoader />
- ) : lastSeen?.timestamp ? (
- <TimestampInfo
- className="text-sm"
- utcTimestamp={lastSeen?.timestamp}
- label={lastSeen.relative}
- />
- ) : (
- <span className="text-foreground-lighter">Never used</span>
- )}
- </div>
- </TableCell>
+ {!hideApiKeyLastUsed && (
+ <TableCell className="py-2 min-w-0 whitespace-nowrap hidden lg:table-cell">
+ <div className="truncate" title={lastSeen?.timestamp.toString() || 'Never used'}>
+ {isLoadingLastSeen ? (
+ <ShimmeringLoader />
+ ) : lastSeen?.timestamp ? (
+ <TimestampInfo
+ className="text-sm"
+ utcTimestamp={lastSeen?.timestamp}
+ label={lastSeen.relative}
+ />
+ ) : (
+ <span className="text-foreground-lighter">Never used</span>
+ )}
+ </div>
+ </TableCell>
+ )}
<TableCell className="py-2">
<div className="flex justify-end">
diff --git a/apps/studio/components/interfaces/APIKeys/SecretAPIKeys.tsx b/apps/studio/components/interfaces/APIKeys/SecretAPIKeys.tsx
index def75dd351d..585bd7d7a09 100644
--- a/apps/studio/components/interfaces/APIKeys/SecretAPIKeys.tsx
+++ b/apps/studio/components/interfaces/APIKeys/SecretAPIKeys.tsx
@@ -2,7 +2,7 @@ import dayjs from 'dayjs'
import { useMemo, useRef } from 'react'
import { toast } from 'sonner'
-import { useParams } from 'common'
+import { useFlag, useParams } from 'common'
import AlertError from 'components/ui/AlertError'
import { FormHeader } from 'components/ui/Forms/FormHeader'
import { useAPIKeyDeleteMutation } from 'data/api-keys/api-key-delete-mutation'
@@ -27,14 +27,24 @@ interface LastSeenData {
[hash: string]: { timestamp: number; relative: string }
}
-function useLastSeen(projectRef: string): { data?: LastSeenData; isLoading: boolean } {
+function useLastSeen(
+ projectRef: string,
+ enabled?: boolean
+): {
+ data?: LastSeenData
+ isLoading: boolean
+} {
const now = useRef(new Date()).current
- const query = useLogsQuery(projectRef, {
- iso_timestamp_start: new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString(),
- iso_timestamp_end: now.toISOString(),
- sql: "-- last-used-secret-api-keys\nSELECT unix_millis(max(timestamp)) as timestamp, apikey.`hash` FROM edge_logs cross join unnest(metadata) as m cross join unnest(m.request) as request cross join unnest(request.sb) as sb cross join unnest(sb.apikey) as sbapikey cross join unnest(sbapikey.apikey) as apikey WHERE apikey.error is null and apikey.`hash` is not null and apikey.prefix like 'sb_secret_%' GROUP BY apikey.`hash`",
- })
+ const query = useLogsQuery(
+ projectRef,
+ {
+ iso_timestamp_start: new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString(),
+ iso_timestamp_end: now.toISOString(),
+ sql: "-- last-used-secret-api-keys\nSELECT unix_millis(max(timestamp)) as timestamp, apikey.`hash` FROM edge_logs cross join unnest(metadata) as m cross join unnest(m.request) as request cross join unnest(request.sb) as sb cross join unnest(sb.apikey) as sbapikey cross join unnest(sbapikey.apikey) as apikey WHERE apikey.error is null and apikey.`hash` is not null and apikey.prefix like 'sb_secret_%' GROUP BY apikey.`hash`",
+ },
+ enabled
+ )
return useMemo(() => {
if (query.isLoading || !query.logData) {
@@ -69,7 +79,11 @@ export const SecretAPIKeys = () => {
isError: isErrorApiKeys,
} = useAPIKeysQuery({ projectRef, reveal: false }, { enabled: canReadAPIKeys })
- const { data: lastSeen, isLoading: isLoadingLastSeen } = useLastSeen(projectRef ?? '')
+ const hideApiKeyLastUsed = useFlag('HideApiKeyLastUsed')
+ const { data: lastSeen, isLoading: isLoadingLastSeen } = useLastSeen(
+ projectRef ?? '',
+ !hideApiKeyLastUsed
+ )
const secretApiKeys = useMemo(
() =>
@@ -150,7 +164,9 @@ export const SecretAPIKeys = () => {
<TableRow className="bg-200">
<TableHead>Name</TableHead>
<TableHead>API Key</TableHead>
- <TableHead className="hidden lg:table-cell">Last Used</TableHead>
+ {!hideApiKeyLastUsed && (
+ <TableHead className="hidden lg:table-cell">Last Used</TableHead>
+ )}
<TableHead />
</TableRow>
</TableHeader>
diff --git a/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx b/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx
index 1a22d603d91..da3eaea4007 100644
--- a/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx
+++ b/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx
@@ -5,7 +5,7 @@ import Link from 'next/link'
import { useMemo } from 'react'
import { toast } from 'sonner'
-import { useParams } from 'common'
+import { useFlag, useParams } from 'common'
import Panel from 'components/ui/Panel'
import { useJwtSecretUpdatingStatusQuery } from 'data/config/jwt-secret-updating-status-query'
import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
@@ -51,12 +51,19 @@ export const DisplayApiSettings = ({
// api keys should not be empty. However it can be populated with a delay on project creation
const isApiKeysEmpty = apiKeys.length === 0
+ const hideApiKeyLastUsed = useFlag('HideApiKeyLastUsed')
const { isLoading: isLoadingLastUsed, logData: lastUsedLogData } = useLastUsedAPIKeysLogQuery(
- projectRef!
+ projectRef!,
+ !hideApiKeyLastUsed
)
const lastUsedAPIKeys = useMemo(() => {
- if (apiKeys.length < 1 || !lastUsedLogData || lastUsedLogData.length < 1) {
+ if (
+ apiKeys.length < 1 ||
+ !lastUsedLogData ||
+ lastUsedLogData.length < 1 ||
+ hideApiKeyLastUsed
+ ) {
return {}
}
@@ -67,7 +74,7 @@ export const DisplayApiSettings = ({
console.error(e)
return {}
}
- }, [lastUsedLogData, apiKeys])
+ }, [lastUsedLogData, apiKeys, hideApiKeyLastUsed])
return (
<Panel
@@ -199,14 +206,16 @@ export const DisplayApiSettings = ({
/>
</FormLayout>
- <div
- className="pt-2 text-foreground-lighter w-full text-sm data-[invisible=true]:invisible"
- data-invisible={isLoadingLastUsed}
- >
- {lastUsedAPIKeys[x.api_key]
- ? `Last request was ${lastUsedAPIKeys[x.api_key]} ago.`
- : 'No requests in the past 24 hours.'}
- </div>
+ {!hideApiKeyLastUsed && (
+ <div
+ className="pt-2 text-foreground-lighter w-full text-sm data-[invisible=true]:invisible"
+ data-invisible={isLoadingLastUsed}
+ >
+ {lastUsedAPIKeys[x.api_key]
+ ? `Last request was ${lastUsedAPIKeys[x.api_key]} ago.`
+ : 'No requests in the past 24 hours.'}
+ </div>
+ )}
</Panel.Content>
))
)}
diff --git a/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.utils.ts b/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.utils.ts
index ae9fc2d3b8c..e1b162d8f8f 100644
--- a/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.utils.ts
+++ b/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.utils.ts
@@ -3,13 +3,17 @@ import { useRef } from 'react'
import useLogsQuery from 'hooks/analytics/useLogsQuery'
-export function useLastUsedAPIKeysLogQuery(projectRef: string) {
+export function useLastUsedAPIKeysLogQuery(projectRef: string, enabled?: boolean) {
const now = useRef(new Date()).current
- return useLogsQuery(projectRef, {
- iso_timestamp_start: new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString(),
- iso_timestamp_end: now.toISOString(),
- sql: "-- last-used-anon--service_role-api-keys\nSELECT unix_millis(max(timestamp)) as timestamp, payload.role, payload.signature_prefix FROM edge_logs cross join unnest(metadata) as m cross join unnest(m.request) as request cross join unnest(request.sb) as sb cross join unnest(sb.jwt) as jwt cross join unnest(jwt.apikey) as apikey cross join unnest(apikey.payload) as payload WHERE apikey.invalid is null and payload.issuer = 'supabase' and payload.algorithm = 'HS256' and payload.role in ('anon', 'service_role') GROUP BY payload.role, payload.signature_prefix",
- })
+ return useLogsQuery(
+ projectRef,
+ {
+ iso_timestamp_start: new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString(),
+ iso_timestamp_end: now.toISOString(),
+ sql: "-- last-used-anon--service_role-api-keys\nSELECT unix_millis(max(timestamp)) as timestamp, payload.role, payload.signature_prefix FROM edge_logs cross join unnest(metadata) as m cross join unnest(m.request) as request cross join unnest(request.sb) as sb cross join unnest(sb.jwt) as jwt cross join unnest(jwt.apikey) as apikey cross join unnest(apikey.payload) as payload WHERE apikey.invalid is null and payload.issuer = 'supabase' and payload.algorithm = 'HS256' and payload.role in ('anon', 'service_role') GROUP BY payload.role, payload.signature_prefix",
+ },
+ enabled
+ )
}
export function getLastUsedAPIKeys(