diff options
| author | Mohamed Bassem <me@mbassem.com> | 2026-02-01 11:05:30 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-01 11:05:30 +0000 |
| commit | e516a525bca6f319a2f003e9677624e968b277bf (patch) | |
| tree | dd467b85f5f3a238f72ec6c76ce42eceb65f20b3 /apps/web | |
| parent | cc638c2a996a5487b101b1306c524eaaf8802604 (diff) | |
| download | karakeep-e516a525bca6f319a2f003e9677624e968b277bf.tar.zst | |
refactor: centralize auth imports through new client module (#2437)
* refactor(web): centralize next-auth client-side utilities
Create lib/auth/client.ts to re-export all next-auth/react APIs (useSession,
signIn, signOut, SessionProvider) from a single location. This prepares
for future auth provider replacement by isolating the next-auth dependency.
https://claude.ai/code/session_01RLLL6SquzmegG6wKHdT3Fm
* format
---------
Co-authored-by: Claude <noreply@anthropic.com>
Diffstat (limited to 'apps/web')
| -rw-r--r-- | apps/web/app/logout/page.tsx | 2 | ||||
| -rw-r--r-- | apps/web/app/reader/[bookmarkId]/page.tsx | 2 | ||||
| -rw-r--r-- | apps/web/components/admin/UserList.tsx | 2 | ||||
| -rw-r--r-- | apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx | 2 | ||||
| -rw-r--r-- | apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx | 2 | ||||
| -rw-r--r-- | apps/web/components/dashboard/bookmarks/TagList.tsx | 2 | ||||
| -rw-r--r-- | apps/web/components/dashboard/header/ProfileOptions.tsx | 2 | ||||
| -rw-r--r-- | apps/web/components/dashboard/preview/BookmarkPreview.tsx | 2 | ||||
| -rw-r--r-- | apps/web/components/dashboard/preview/LinkContentSection.tsx | 2 | ||||
| -rw-r--r-- | apps/web/components/invite/InviteAcceptForm.tsx | 2 | ||||
| -rw-r--r-- | apps/web/components/signin/CredentialsForm.tsx | 2 | ||||
| -rw-r--r-- | apps/web/components/signin/SignInProviderButton.tsx | 2 | ||||
| -rw-r--r-- | apps/web/components/signup/SignUpForm.tsx | 2 | ||||
| -rw-r--r-- | apps/web/lib/auth/client.ts | 11 | ||||
| -rw-r--r-- | apps/web/lib/providers.tsx | 3 |
15 files changed, 25 insertions, 15 deletions
diff --git a/apps/web/app/logout/page.tsx b/apps/web/app/logout/page.tsx index 91ad684d..1e43622e 100644 --- a/apps/web/app/logout/page.tsx +++ b/apps/web/app/logout/page.tsx @@ -2,7 +2,7 @@ import { useEffect } from "react"; import { useRouter } from "next/navigation"; -import { signOut } from "next-auth/react"; +import { signOut } from "@/lib/auth/client"; import { useSearchHistory } from "@karakeep/shared-react/hooks/search-history"; diff --git a/apps/web/app/reader/[bookmarkId]/page.tsx b/apps/web/app/reader/[bookmarkId]/page.tsx index 5e77279f..3eba7c7a 100644 --- a/apps/web/app/reader/[bookmarkId]/page.tsx +++ b/apps/web/app/reader/[bookmarkId]/page.tsx @@ -8,9 +8,9 @@ import ReaderView from "@/components/dashboard/preview/ReaderView"; import { Button } from "@/components/ui/button"; import { FullPageSpinner } from "@/components/ui/full-page-spinner"; import { Separator } from "@/components/ui/separator"; +import { useSession } from "@/lib/auth/client"; import { useReaderSettings } from "@/lib/readerSettings"; import { HighlighterIcon as Highlight, Printer, X } from "lucide-react"; -import { useSession } from "next-auth/react"; import { api } from "@karakeep/shared-react/trpc"; import { BookmarkTypes } from "@karakeep/shared/types/bookmarks"; diff --git a/apps/web/components/admin/UserList.tsx b/apps/web/components/admin/UserList.tsx index 91467f94..69f9e3b9 100644 --- a/apps/web/components/admin/UserList.tsx +++ b/apps/web/components/admin/UserList.tsx @@ -11,10 +11,10 @@ import { TableHeader, TableRow, } from "@/components/ui/table"; +import { useSession } from "@/lib/auth/client"; import { useTranslation } from "@/lib/i18n/client"; import { api } from "@/lib/trpc"; import { Check, KeyRound, Pencil, Trash, UserPlus, X } from "lucide-react"; -import { useSession } from "next-auth/react"; import ActionConfirmingDialog from "../ui/action-confirming-dialog"; import AddUserDialog from "./AddUserDialog"; diff --git a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx index 2f02f095..3e27dbcb 100644 --- a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx +++ b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx @@ -5,6 +5,7 @@ import type { ReactNode } from "react"; import { useEffect, useState } from "react"; import Image from "next/image"; import Link from "next/link"; +import { useSession } from "@/lib/auth/client"; import useBulkActionsStore from "@/lib/bulkActions"; import { api } from "@/lib/trpc"; import { @@ -14,7 +15,6 @@ import { } from "@/lib/userLocalSettings/bookmarksLayout"; import { cn } from "@/lib/utils"; import { Check, Image as ImageIcon, NotebookPen } from "lucide-react"; -import { useSession } from "next-auth/react"; import { useTheme } from "next-themes"; import type { ZBookmark } from "@karakeep/shared/types/bookmarks"; diff --git a/apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx b/apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx index 3d295925..c161853d 100644 --- a/apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx +++ b/apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx @@ -11,6 +11,7 @@ import { DropdownMenuSubTrigger, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; +import { useSession } from "@/lib/auth/client"; import { useClientConfig } from "@/lib/clientConfig"; import useUpload from "@/lib/hooks/upload-file"; import { useTranslation } from "@/lib/i18n/client"; @@ -29,7 +30,6 @@ import { SquarePen, Trash2, } from "lucide-react"; -import { useSession } from "next-auth/react"; import { toast } from "sonner"; import type { diff --git a/apps/web/components/dashboard/bookmarks/TagList.tsx b/apps/web/components/dashboard/bookmarks/TagList.tsx index f1c319ea..88611c52 100644 --- a/apps/web/components/dashboard/bookmarks/TagList.tsx +++ b/apps/web/components/dashboard/bookmarks/TagList.tsx @@ -1,8 +1,8 @@ import Link from "next/link"; import { badgeVariants } from "@/components/ui/badge"; import { Skeleton } from "@/components/ui/skeleton"; +import { useSession } from "@/lib/auth/client"; import { cn } from "@/lib/utils"; -import { useSession } from "next-auth/react"; import type { ZBookmark } from "@karakeep/shared/types/bookmarks"; diff --git a/apps/web/components/dashboard/header/ProfileOptions.tsx b/apps/web/components/dashboard/header/ProfileOptions.tsx index 5199bdec..b09d276e 100644 --- a/apps/web/components/dashboard/header/ProfileOptions.tsx +++ b/apps/web/components/dashboard/header/ProfileOptions.tsx @@ -13,9 +13,9 @@ import { } from "@/components/ui/dropdown-menu"; import { Separator } from "@/components/ui/separator"; import { UserAvatar } from "@/components/ui/user-avatar"; +import { useSession } from "@/lib/auth/client"; import { useTranslation } from "@/lib/i18n/client"; import { LogOut, Moon, Paintbrush, Settings, Shield, Sun } from "lucide-react"; -import { useSession } from "next-auth/react"; import { useTheme } from "next-themes"; import { useWhoAmI } from "@karakeep/shared-react/hooks/users"; diff --git a/apps/web/components/dashboard/preview/BookmarkPreview.tsx b/apps/web/components/dashboard/preview/BookmarkPreview.tsx index 7e6bf814..d56bfb6a 100644 --- a/apps/web/components/dashboard/preview/BookmarkPreview.tsx +++ b/apps/web/components/dashboard/preview/BookmarkPreview.tsx @@ -13,11 +13,11 @@ import { TooltipPortal, TooltipTrigger, } from "@/components/ui/tooltip"; +import { useSession } from "@/lib/auth/client"; import useRelativeTime from "@/lib/hooks/relative-time"; import { useTranslation } from "@/lib/i18n/client"; import { api } from "@/lib/trpc"; import { Building, CalendarDays, ExternalLink, User } from "lucide-react"; -import { useSession } from "next-auth/react"; import { BookmarkTypes, ZBookmark } from "@karakeep/shared/types/bookmarks"; import { diff --git a/apps/web/components/dashboard/preview/LinkContentSection.tsx b/apps/web/components/dashboard/preview/LinkContentSection.tsx index 5fb51784..f4e344ac 100644 --- a/apps/web/components/dashboard/preview/LinkContentSection.tsx +++ b/apps/web/components/dashboard/preview/LinkContentSection.tsx @@ -16,6 +16,7 @@ import { TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; +import { useSession } from "@/lib/auth/client"; import { Trans, useTranslation } from "@/lib/i18n/client"; import { useReaderSettings } from "@/lib/readerSettings"; import { @@ -28,7 +29,6 @@ import { Info, Video, } from "lucide-react"; -import { useSession } from "next-auth/react"; import { useQueryState } from "nuqs"; import { ErrorBoundary } from "react-error-boundary"; diff --git a/apps/web/components/invite/InviteAcceptForm.tsx b/apps/web/components/invite/InviteAcceptForm.tsx index 95a0e1eb..5fa166c0 100644 --- a/apps/web/components/invite/InviteAcceptForm.tsx +++ b/apps/web/components/invite/InviteAcceptForm.tsx @@ -21,11 +21,11 @@ import { FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; +import { signIn } from "@/lib/auth/client"; import { api } from "@/lib/trpc"; import { zodResolver } from "@hookform/resolvers/zod"; import { TRPCClientError } from "@trpc/client"; import { AlertCircle, Clock, Loader2, Mail, UserPlus } from "lucide-react"; -import { signIn } from "next-auth/react"; import { useForm } from "react-hook-form"; import { z } from "zod"; diff --git a/apps/web/components/signin/CredentialsForm.tsx b/apps/web/components/signin/CredentialsForm.tsx index 4a4a0533..0ff5b1d0 100644 --- a/apps/web/components/signin/CredentialsForm.tsx +++ b/apps/web/components/signin/CredentialsForm.tsx @@ -14,10 +14,10 @@ import { FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; +import { signIn } from "@/lib/auth/client"; import { useClientConfig } from "@/lib/clientConfig"; import { zodResolver } from "@hookform/resolvers/zod"; import { AlertCircle, Lock } from "lucide-react"; -import { signIn } from "next-auth/react"; import { useForm } from "react-hook-form"; import { z } from "zod"; diff --git a/apps/web/components/signin/SignInProviderButton.tsx b/apps/web/components/signin/SignInProviderButton.tsx index edb411e6..4b218e2a 100644 --- a/apps/web/components/signin/SignInProviderButton.tsx +++ b/apps/web/components/signin/SignInProviderButton.tsx @@ -1,7 +1,7 @@ "use client"; import { Button } from "@/components/ui/button"; -import { signIn } from "next-auth/react"; +import { signIn } from "@/lib/auth/client"; export default function SignInProviderButton({ provider, diff --git a/apps/web/components/signup/SignUpForm.tsx b/apps/web/components/signup/SignUpForm.tsx index 340b461a..845c6d1e 100644 --- a/apps/web/components/signup/SignUpForm.tsx +++ b/apps/web/components/signup/SignUpForm.tsx @@ -23,13 +23,13 @@ import { FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; +import { signIn } from "@/lib/auth/client"; import { useClientConfig } from "@/lib/clientConfig"; import { api } from "@/lib/trpc"; import { zodResolver } from "@hookform/resolvers/zod"; import { Turnstile } from "@marsidev/react-turnstile"; import { TRPCClientError } from "@trpc/client"; import { AlertCircle, UserX } from "lucide-react"; -import { signIn } from "next-auth/react"; import { useForm } from "react-hook-form"; import { z } from "zod"; diff --git a/apps/web/lib/auth/client.ts b/apps/web/lib/auth/client.ts new file mode 100644 index 00000000..7e13f798 --- /dev/null +++ b/apps/web/lib/auth/client.ts @@ -0,0 +1,11 @@ +"use client"; + +/** + * Centralized client-side auth utilities. + * This module re-exports next-auth/react functions to allow for easier + * future migration to a different auth provider. + */ + +export { SessionProvider, signIn, signOut, useSession } from "next-auth/react"; + +export type { Session } from "next-auth"; diff --git a/apps/web/lib/providers.tsx b/apps/web/lib/providers.tsx index a3debdb9..dd4e62e7 100644 --- a/apps/web/lib/providers.tsx +++ b/apps/web/lib/providers.tsx @@ -1,14 +1,13 @@ "use client"; import type { UserLocalSettings } from "@/lib/userLocalSettings/types"; -import type { Session } from "next-auth"; import React, { useState } from "react"; import { ThemeProvider } from "@/components/theme-provider"; import { TooltipProvider } from "@/components/ui/tooltip"; +import { Session, SessionProvider } from "@/lib/auth/client"; import { UserLocalSettingsCtx } from "@/lib/userLocalSettings/bookmarksLayout"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { httpBatchLink, loggerLink } from "@trpc/client"; -import { SessionProvider } from "next-auth/react"; import superjson from "superjson"; import type { ClientConfig } from "@karakeep/shared/config"; |
