Skip to content

Commit 7b22750

Browse files
refactor(web): migrate all auth to withAuthV2/withOptionalAuthV2
Replace all usages of the legacy withAuth and withOrgMembership helpers with the newer withAuthV2, withOptionalAuthV2, and withMinimumOrgRole APIs. This consolidates auth into a single context object that provides user, org, role, and a user-scoped prisma client, eliminating the need for separate domain parameters and nested auth wrappers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 331f025 commit 7b22750

File tree

22 files changed

+307
-469
lines changed

22 files changed

+307
-469
lines changed

packages/web/src/actions.ts

Lines changed: 252 additions & 399 deletions
Large diffs are not rendered by default.

packages/web/src/app/[domain]/chat/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default async function Page(props: PageProps) {
104104

105105
const languageModels = await getConfiguredLanguageModelsInfo();
106106
const repos = await getRepos();
107-
const searchContexts = await getSearchContexts(params.domain);
107+
const searchContexts = await getSearchContexts();
108108
const chatInfo = await getChatInfo({ chatId: params.id });
109109
const chatHistory = session ? await getUserChatHistory() : [];
110110

packages/web/src/app/[domain]/chat/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface PageProps {
2727
export default async function Page(props: PageProps) {
2828
const params = await props.params;
2929
const languageModels = await getConfiguredLanguageModelsInfo();
30-
const searchContexts = await getSearchContexts(params.domain);
30+
const searchContexts = await getSearchContexts();
3131
const allRepos = await getRepos();
3232
const session = await auth();
3333
const chatHistory = session ? await getUserChatHistory() : [];

packages/web/src/app/[domain]/components/navigationMenu/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const NavigationMenu = async ({
3333
throw new ServiceErrorException(repoStats);
3434
}
3535

36-
const role = isAuthenticated ? await getCurrentUserRole(domain) : null;
36+
const role = isAuthenticated ? await getCurrentUserRole() : null;
3737
if (isServiceError(role)) {
3838
throw new ServiceErrorException(role);
3939
}
@@ -43,7 +43,7 @@ export const NavigationMenu = async ({
4343
return null;
4444
}
4545

46-
const joinRequests = await getOrgAccountRequests(domain);
46+
const joinRequests = await getOrgAccountRequests();
4747
if (isServiceError(joinRequests)) {
4848
throw new ServiceErrorException(joinRequests);
4949
}

packages/web/src/app/[domain]/components/searchBar/useSuggestionsData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const useSuggestionsData = ({
107107

108108
const { data: searchContextSuggestions, isLoading: _isLoadingSearchContexts } = useQuery({
109109
queryKey: ["searchContexts", domain],
110-
queryFn: () => getSearchContexts(domain),
110+
queryFn: () => getSearchContexts(),
111111
select: (data): Suggestion[] => {
112112
if (isServiceError(data)) {
113113
return [];

packages/web/src/app/[domain]/repos/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default async function RepoDetailPage({ params }: { params: Promise<{ id:
5252

5353
const repoMetadata = repoMetadataSchema.parse(repo.metadata);
5454

55-
const userRole = await getCurrentUserRole(SINGLE_TENANT_ORG_DOMAIN);
55+
const userRole = await getCurrentUserRole();
5656
if (isServiceError(userRole)) {
5757
throw new ServiceErrorException(userRole);
5858
}

packages/web/src/app/[domain]/repos/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default async function Layout(
2424
throw new ServiceErrorException(repoStats);
2525
}
2626

27-
const userRoleInOrg = await getCurrentUserRole(domain);
27+
const userRoleInOrg = await getCurrentUserRole();
2828

2929
return (
3030
<div className="min-h-screen flex flex-col">

packages/web/src/app/[domain]/settings/apiKeys/apiKeysPage.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Input } from "@/components/ui/input";
77
import { isServiceError } from "@/lib/utils";
88
import { Copy, Check, AlertTriangle, Loader2, Plus } from "lucide-react";
99
import { useCallback, useEffect, useMemo, useState } from "react";
10-
import { useDomain } from "@/hooks/useDomain";
1110
import { useToast } from "@/components/hooks/use-toast";
1211
import useCaptureEvent from "@/hooks/useCaptureEvent";
1312
import { DataTable } from "@/components/ui/data-table";
@@ -16,7 +15,6 @@ import { Skeleton } from "@/components/ui/skeleton";
1615
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
1716

1817
export function ApiKeysPage({ canCreateApiKey }: { canCreateApiKey: boolean }) {
19-
const domain = useDomain();
2018
const { toast } = useToast();
2119
const captureEvent = useCaptureEvent();
2220

@@ -33,7 +31,7 @@ export function ApiKeysPage({ canCreateApiKey }: { canCreateApiKey: boolean }) {
3331
setIsLoading(true);
3432
setError(null);
3533
try {
36-
const keys = await getUserApiKeys(domain);
34+
const keys = await getUserApiKeys();
3735
if (isServiceError(keys)) {
3836
setError("Failed to load API keys");
3937
toast({
@@ -55,7 +53,7 @@ export function ApiKeysPage({ canCreateApiKey }: { canCreateApiKey: boolean }) {
5553
} finally {
5654
setIsLoading(false);
5755
}
58-
}, [domain, toast]);
56+
}, [toast]);
5957

6058
useEffect(() => {
6159
loadApiKeys();
@@ -73,7 +71,7 @@ export function ApiKeysPage({ canCreateApiKey }: { canCreateApiKey: boolean }) {
7371

7472
setIsCreatingKey(true);
7573
try {
76-
const result = await createApiKey(newKeyName.trim(), domain);
74+
const result = await createApiKey(newKeyName.trim());
7775
if (isServiceError(result)) {
7876
toast({
7977
title: "Error",

packages/web/src/app/[domain]/settings/apiKeys/columns.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ColumnDef } from "@tanstack/react-table"
44
import { ArrowUpDown, Key, Trash2 } from "lucide-react"
55
import { Button } from "@/components/ui/button"
66
import { deleteApiKey } from "@/actions"
7-
import { useParams } from "next/navigation"
87
import {
98
AlertDialog,
109
AlertDialogAction,
@@ -27,14 +26,13 @@ export type ApiKeyColumnInfo = {
2726

2827
// Component for the actions cell to properly use React hooks
2928
function ApiKeyActions({ apiKey }: { apiKey: ApiKeyColumnInfo }) {
30-
const params = useParams<{ domain: string }>()
3129
const [isPending, setIsPending] = useState(false)
3230
const { toast } = useToast()
3331

3432
const handleDelete = async () => {
3533
setIsPending(true)
3634
try {
37-
await deleteApiKey(apiKey.name, params.domain)
35+
await deleteApiKey(apiKey.name)
3836
window.location.reload()
3937
} catch (error) {
4038
console.error("Failed to delete API key", error)

packages/web/src/app/[domain]/settings/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const getSidebarNavItems = async () =>
7070
withAuthV2(async ({ role }) => {
7171
let numJoinRequests: number | undefined;
7272
if (role === OrgRole.OWNER) {
73-
const requests = await getOrgAccountRequests(SINGLE_TENANT_ORG_DOMAIN);
73+
const requests = await getOrgAccountRequests();
7474
if (isServiceError(requests)) {
7575
throw new ServiceErrorException(requests);
7676
}

0 commit comments

Comments
 (0)