diff --git a/app/invitations/page.tsx b/app/invitations/page.tsx index 7a60146..9fd9f69 100644 --- a/app/invitations/page.tsx +++ b/app/invitations/page.tsx @@ -1,4 +1,5 @@ -import { auth } from '@/auth' +import { getServerSession } from 'next-auth' +import { authOptions } from '@/pages/api/auth/[...nextauth]' import { redirect } from 'next/navigation' import { getInvitations } from '@/lib/sharing-actions' import InvitationCard from '@/components/InvitationCard' @@ -27,7 +28,7 @@ type Invitation = { } export default async function InvitationsPage() { - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user) { redirect('/auth/login') diff --git a/app/list/[id]/item/[itemId]/edit/page.tsx b/app/list/[id]/item/[itemId]/edit/page.tsx index 10cb47c..d56f3e0 100644 --- a/app/list/[id]/item/[itemId]/edit/page.tsx +++ b/app/list/[id]/item/[itemId]/edit/page.tsx @@ -1,7 +1,8 @@ import { notFound } from 'next/navigation' import { getItem } from '@/lib/actions' import { canEditList } from '@/lib/permissions' -import { auth } from '@/auth' +import { getServerSession } from 'next-auth' +import { authOptions } from '@/pages/api/auth/[...nextauth]' import ItemForm from '@/components/ItemForm' import Link from 'next/link' import { ArrowLeft } from 'lucide-react' @@ -16,7 +17,7 @@ interface PageProps { } export default async function EditItemPage({ params }: PageProps) { - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { notFound() } diff --git a/app/list/[id]/item/[itemId]/page.tsx b/app/list/[id]/item/[itemId]/page.tsx index 410759d..8110336 100644 --- a/app/list/[id]/item/[itemId]/page.tsx +++ b/app/list/[id]/item/[itemId]/page.tsx @@ -1,7 +1,8 @@ import { notFound } from 'next/navigation' import { getItem } from '@/lib/actions' import { canEditList } from '@/lib/permissions' -import { auth } from '@/auth' +import { getServerSession } from 'next-auth' +import { authOptions } from '@/pages/api/auth/[...nextauth]' import ItemDetail from '@/components/ItemDetail' import Link from 'next/link' import { ArrowLeft, Edit } from 'lucide-react' @@ -18,7 +19,7 @@ interface PageProps { } export default async function ItemDetailPage({ params }: PageProps) { - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { notFound() } diff --git a/app/list/[id]/page.tsx b/app/list/[id]/page.tsx index 3c9dd09..28b1278 100644 --- a/app/list/[id]/page.tsx +++ b/app/list/[id]/page.tsx @@ -1,6 +1,7 @@ import { getListWithItems } from '@/lib/actions' import { getPermission } from '@/lib/permissions' -import { auth } from '@/auth' +import { getServerSession } from 'next-auth' +import { authOptions } from '@/pages/api/auth/[...nextauth]' import { notFound } from 'next/navigation' import Link from 'next/link' import { ArrowLeft } from 'lucide-react' @@ -10,7 +11,7 @@ import ListDetailView from '@/components/ListDetailView' export const dynamic = 'force-dynamic' export default async function ListDetailPage({ params }: { params: { id: string } }) { - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { notFound() } diff --git a/app/page.tsx b/app/page.tsx index f8c84c9..8906f1d 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -4,13 +4,14 @@ import NewListButton from '@/components/NewListButton' import GlobalSearch from '@/components/GlobalSearch' import EmptyState from '@/components/EmptyState' import Link from 'next/link' -import { auth } from '@/auth' +import { getServerSession } from 'next-auth' +import { authOptions } from '@/pages/api/auth/[...nextauth]' import { redirect } from 'next/navigation' export const dynamic = 'force-dynamic' export default async function Home() { - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user) { redirect('/auth/login') diff --git a/app/profile/page.tsx b/app/profile/page.tsx index e75b53c..46c9435 100644 --- a/app/profile/page.tsx +++ b/app/profile/page.tsx @@ -1,5 +1,6 @@ import { redirect } from 'next/navigation' -import { auth } from '@/auth' +import { getServerSession } from 'next-auth' +import { authOptions } from '@/pages/api/auth/[...nextauth]' import { getUserProfile } from '@/lib/auth-actions' import ProfileForm from '@/components/ProfileForm' import PasswordChangeForm from '@/components/PasswordChangeForm' @@ -11,7 +12,7 @@ export const metadata = { } export default async function ProfilePage() { - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { redirect('/auth/login') diff --git a/lib/__tests__/auth-actions.test.ts b/lib/__tests__/auth-actions.test.ts index f328f33..f7be789 100644 --- a/lib/__tests__/auth-actions.test.ts +++ b/lib/__tests__/auth-actions.test.ts @@ -15,7 +15,7 @@ vi.mock('@/auth', () => ({ // Import after mocking import { registerUser, loginUser } from '../auth-actions' -import { signIn } from '@/auth' +import { signIn } from 'next-auth/react' describe('registerUser', () => { // Clean up test users after each test diff --git a/lib/actions.ts b/lib/actions.ts index 93c77f9..733c1d7 100644 --- a/lib/actions.ts +++ b/lib/actions.ts @@ -2,7 +2,8 @@ import { prisma } from './db' import { revalidatePath } from 'next/cache' -import { auth } from '@/auth' +import { getServerSession } from 'next-auth' +import { authOptions } from '@/pages/api/auth/[...nextauth]' import { validateListTitle, validateItemTitle, @@ -49,7 +50,7 @@ async function retryOperation( export async function getLists() { try { // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to view lists') } @@ -109,7 +110,7 @@ export async function getLists() { export async function createList(title: string, color: string = '#3B82F6') { try { // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to create lists') } @@ -157,7 +158,7 @@ export async function getListWithItems(listId: string) { } // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to view lists') } @@ -228,7 +229,7 @@ export async function getItem(itemId: string) { } // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to view items') } @@ -305,7 +306,7 @@ export async function createItem( } // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to create items') } @@ -387,7 +388,7 @@ export async function toggleItem(itemId: string) { } // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to update items') } @@ -465,7 +466,7 @@ export async function updateItem( } // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to update items') } @@ -560,7 +561,7 @@ export async function deleteItem(itemId: string) { } // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to delete items') } @@ -626,7 +627,7 @@ export async function deleteList(listId: string) { } // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to delete lists') } @@ -677,7 +678,7 @@ export async function updateList( } // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to update lists') } @@ -751,7 +752,7 @@ export async function searchItems(query: string, listId?: string) { } // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to search items') } @@ -878,7 +879,7 @@ export async function getItemsByFilter( ) { try { // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to filter items') } diff --git a/lib/auth-actions.ts b/lib/auth-actions.ts index c219cd2..eab16f0 100644 --- a/lib/auth-actions.ts +++ b/lib/auth-actions.ts @@ -3,7 +3,7 @@ import { prisma } from './db' import bcrypt from 'bcryptjs' import { z } from 'zod' -import { signIn, signOut } from '@/auth' +import { signIn, signOut } from 'next-auth/react' import { checkRateLimit, resetRateLimit, LOGIN_RATE_LIMIT, REGISTER_RATE_LIMIT } from './rate-limit' import { headers } from 'next/headers' import { getClientIdentifier } from './rate-limit' @@ -196,7 +196,7 @@ export async function logoutUser(): Promise { export async function getCurrentSession() { try { const { auth } = await import('@/auth') - const session = await auth() + const session = await getServerSession(authOptions) return session } catch (error) { console.error('Session retrieval error:', error) diff --git a/lib/migration-actions.ts b/lib/migration-actions.ts index 593bec3..270d54c 100644 --- a/lib/migration-actions.ts +++ b/lib/migration-actions.ts @@ -1,7 +1,8 @@ 'use server' import { prisma } from './db' -import { auth } from '@/auth' +import { getServerSession } from 'next-auth' +import { authOptions } from '@/pages/api/auth/[...nextauth]' /** * Migration utilities for transitioning existing anonymous lists to user-owned lists @@ -71,7 +72,7 @@ export async function getClaimableLists(listIds: string[]): Promise { try { // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { return { success: false, error: 'Unauthorized: Please log in to claim lists' } } @@ -116,7 +117,7 @@ export async function claimLists(listIds: string[]): Promise { */ export async function hasExistingLists(): Promise { try { - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { return false } diff --git a/lib/sharing-actions.ts b/lib/sharing-actions.ts index 88a9e44..3f37316 100644 --- a/lib/sharing-actions.ts +++ b/lib/sharing-actions.ts @@ -2,7 +2,8 @@ import { prisma } from './db' import { revalidatePath } from 'next/cache' -import { auth } from '@/auth' +import { getServerSession } from 'next-auth' +import { authOptions } from '@/pages/api/auth/[...nextauth]' import { z } from 'zod' import { checkRateLimit, INVITATION_RATE_LIMIT } from './rate-limit' @@ -57,7 +58,7 @@ export async function inviteUserToList( ) { try { // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to invite users') } @@ -187,7 +188,7 @@ export async function inviteUserToList( export async function getInvitations() { try { // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id || !session?.user?.email) { throw new Error('Unauthorized: Please log in to view invitations') } @@ -237,7 +238,7 @@ export async function getInvitations() { export async function acceptInvitation(invitationId: string) { try { // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id || !session?.user?.email) { throw new Error('Unauthorized: Please log in to accept invitations') } @@ -345,7 +346,7 @@ export async function acceptInvitation(invitationId: string) { export async function declineInvitation(invitationId: string) { try { // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id || !session?.user?.email) { throw new Error('Unauthorized: Please log in to decline invitations') } @@ -408,7 +409,7 @@ export async function declineInvitation(invitationId: string) { export async function getCollaborators(listId: string) { try { // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to view collaborators') } @@ -488,7 +489,7 @@ export async function updateCollaboratorPermission( ) { try { // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to update permissions') } @@ -566,7 +567,7 @@ export async function removeCollaborator( ) { try { // Get current user session - const session = await auth() + const session = await getServerSession(authOptions) if (!session?.user?.id) { throw new Error('Unauthorized: Please log in to remove collaborators') }