Files
Alaister YoungandAlaister Young 680633ee4f [FE-5108] (part 5) refactor(studio): migrate remaining interfaces off next/link (#54308)
Part 5 of a 6-PR stack migrating all `next/link` imports in
`apps/studio` onto TanStack Router's `Link` (or plain `<a>` for known
external URLs) and removing `compat/next/link.tsx`.

| Part | PR | Scope |
| --- | --- | --- |
| 1 | #54304 | `data/prefetchers/PrefetchableLink.tsx` and
`components/ui/**` |
| 2 | #54305 | `components/layouts/**` and top-level shell components |
| 3 | #54306 | Database, TableGridEditor, Storage, SQLEditor,
BranchManagement, Branching, Functions, Realtime |
| 4 | #54307 | Integrations, Settings, Observability, LogDrains, Issues,
Linter, Reports, QueryPerformance, QuerySources, ConfigDrift,
DiskManagement, Compute |
| **5** | **#54308 ← this PR** | **Remaining `components/interfaces/**`
(Org, Billing, Auth, Support, Home, SignIn, ConnectSheet, etc.)** |
| 6 | #54309 | Remove `compat/next/link.tsx` shim, Vite alias, and
update basePath tests/docs |

Migrates the remaining `components/interfaces/**` directories off
`next/link`, leaving zero `next/link` component imports in
`apps/studio`.

**Changed:**

- Replaced `next/link` across all 73 remaining interface files
(`Organization`, `OrganizationInvite`, `Billing`, `Auth`, `Support`,
`ProjectHome`, `Home`, `Project`, `ProjectCreation`, `ProjectAPIDocs`,
`ApiAuthorization`, `App`, `ConnectSheet`, `SignIn`, `APIKeys`,
`Account`, `CliLogin`, `Docs`, `JwtSecrets`, `Platform`)
- Converted the sole remaining `UrlObject` link (`<Link href={{
pathname: '/sign-in-sso', query }}>`) in `SignInSSOForm.tsx` to `<Link
to="/sign-in-sso" search={query}>`
- Migrated `SupportLink.tsx` onto `DynamicLink`
(`createSupportFormUrl(...)`)
- Standardized external `target="_blank"` anchors with `rel="noreferrer
noopener"`, switched `OverviewMetrics.tsx` observability link to typed
`<Link to="/project/$ref/observability/auth">`, and adopted `InlineLink`
/ `InlineLinkClassName` on inline paragraph links per review feedback

Addresses
[FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link)

## To test

- [ ] Check Organization (billing, usage, team, documents, AWS
Marketplace), Auth (providers, templates, rate limits, users, OAuth
apps), Support form/links, Project Home, Connect sheet, and Sign-In/SSO
links
- [ ] Verify `SignInWithSSOButton` preserves query params when
navigating to `/sign-in-sso`
- [ ] Verify `SupportLink` pre-populates support form query parameters
cleanly

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-12-01 17:33:03 +08:00

227 lines
7.9 KiB
TypeScript

import { Link } from '@tanstack/react-router'
import { useFlag, useParams } from 'common'
import { ExternalLinkIcon, RefreshCwIcon } from 'lucide-react'
import { useQueryState } from 'nuqs'
import { useEffect } from 'react'
import { Button, cn, CriticalIcon, Separator } from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import { TimestampInfo } from 'ui-patterns/TimestampInfo'
import { PANEL_PADDING } from './Users.constants'
import { LOGS_TABLES } from '@/components/interfaces/Settings/Logs/Logs.constants'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { User } from '@/data/auth/users-infinite-query'
import { pickLogsQueryBuilder } from '@/data/logs/logs-endpoint'
import { analyticsLiteral, safeSql } from '@/data/logs/safe-analytics-sql'
import useLogsPreview from '@/hooks/analytics/useLogsPreview'
import { useLogsUrlState } from '@/hooks/analytics/useLogsUrlState'
interface UserLogsProps {
user: User
}
const getApiLogsQuery = (userId: string) => safeSql`
select
cast(timestamp as datetime) as timestamp,
event_message,
metadata
from edge_logs
where metadata[SAFE_OFFSET(0)].request[SAFE_OFFSET(0)].sb[SAFE_OFFSET(0)].auth_user = ${analyticsLiteral(userId)}
limit 100
`
const getApiLogsQueryOtel = (userId: string) => safeSql`
select
timestamp,
event_message,
log_attributes
from logs
where source = 'auth_logs'
and log_attributes['auth_event.actor_id'] = ${analyticsLiteral(userId)}
order by timestamp desc
limit 100
`
export const UserLogs = ({ user }: UserLogsProps) => {
const { ref } = useParams()
const useOtel = useFlag('otelLegacyLogs')
const { filters, setFilters } = useLogsUrlState()
const [, setFiltersValue] = useQueryState('f')
const apiLogsQuery = pickLogsQueryBuilder(
useOtel,
getApiLogsQueryOtel,
getApiLogsQuery
)(user.id ?? '')
const {
logData: authLogs,
isSuccess: isSuccessAuthLogs,
isLoading: isLoadingAuthLogs,
refresh,
} = useLogsPreview({
projectRef: ref as string,
table: LOGS_TABLES.auth,
filterOverride: { search_query: user.id },
limit: 5,
})
useEffect(() => {
if (user.id) setFilters({ ...filters, search_query: user.id })
return () => {
setFiltersValue(null)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [user.id])
return (
<div>
<div className={cn('flex flex-col gap-y-3', PANEL_PADDING)}>
<div>
<p>Auth API logs</p>
<p className="text-sm text-foreground-light">View logs associated with this Auth user</p>
</div>
<Button asChild className="w-min">
<Link
to="/project/$ref/logs/explorer"
params={{ ref: ref ?? '_' }}
search={{ q: apiLogsQuery }}
>
Open in Log Explorer
</Link>
</Button>
</div>
<Separator />
<div className={cn('flex flex-col gap-y-3', PANEL_PADDING)}>
<div>
<p>Authentication logs</p>
<p className="text-sm text-foreground-light">
Latest logs from authentication for this user in the past hour
</p>
</div>
{/* [Joshen] This whole thing here i reckon we can shift to a component, if in the future we wanna add more user logs */}
<div className="flex items-center justify-between">
<div className="flex items-center">
<Button
variant={'status_code' in filters ? 'default' : 'secondary'}
className="rounded-r-none border-r-0"
disabled={isLoadingAuthLogs}
onClick={() => setFilters({ search_query: user.id })}
>
Show all
</Button>
<div className="border-button border border-l-0 py-3" />
<Button
variant={'status_code' in filters ? 'secondary' : 'default'}
className="rounded-l-none border-l-0"
disabled={isLoadingAuthLogs}
onClick={() =>
setFilters({
search_query: user.id,
status_code: { client_error: true, server_error: true },
})
}
>
Error only
</Button>
</div>
<Button
loading={isLoadingAuthLogs}
disabled={isLoadingAuthLogs}
icon={<RefreshCwIcon />}
onClick={() => refresh()}
>
Refresh
</Button>
</div>
{isLoadingAuthLogs && !isSuccessAuthLogs ? (
<GenericSkeletonLoader />
) : authLogs.length === 0 ? (
<Admonition
type="note"
title="No authentication logs available for this user"
description="Auth events such as logging in will be shown here"
/>
) : (
<div>
<div className="border border-b-0 rounded-t-md divide-y overflow-hidden">
{authLogs.map((log) => {
const status = ((log.status ?? '-') as any).toString()
const is400 = status.startsWith('4')
const is500 = status.startsWith('5')
return (
<div
key={log.id}
className="flex items-center transition font-mono px-2 py-1.5 bg-surface-100 divide-x"
>
<p className="text-xs text-foreground-light min-w-[125px] w-[125px] px-1">
<TimestampInfo utcTimestamp={log.timestamp / 1000} />
</p>
<div className="flex items-center text-xs text-foreground-light h-[22px] min-w-[70px] w-[70px] px-2">
<div
className={cn(
'flex items-center justify-center gap-x-1',
!!log.status && 'border px-1 py-0.5 rounded-sm',
is400
? 'text-warning border-warning bg-warning-300'
: is500
? 'text-destructive border-destructive bg-destructive-300'
: ''
)}
>
{(is400 || is500) && (
<CriticalIcon hideBackground className={cn(is400 && 'text-warning')} />
)}
{status}
</div>
</div>
<p className="group relative flex items-center py-1.5 text-xs text-foreground-light px-2 truncate w-full">
{`${log.path} | ${log.msg}`}
<ButtonTooltip
variant="outline"
asChild
tooltip={{ content: { text: 'Open in logs' } }}
className="px-1.5 absolute right-0 top-0 opacity-0 group-hover:opacity-100 transition bg-background focus-visible:opacity-100"
>
<Link
to="/project/$ref/logs/auth-logs"
params={{ ref: ref ?? '_' }}
search={{ log: log.id }}
>
<ExternalLinkIcon size="12" className="text-foreground-light" />
</Link>
</ButtonTooltip>
</p>
</div>
)
})}
</div>
<Button
block
asChild
variant="outline"
className="transition rounded-t-none text-foreground-light hover:text-foreground"
>
<Link
to="/project/$ref/logs/auth-logs"
params={{ ref: ref ?? '_' }}
search={{ s: user.id }}
>
See more logs
</Link>
</Button>
</div>
)}
</div>
</div>
)
}