Fix all NextAuth v4 imports across codebase

This commit is contained in:
2025-12-02 14:03:13 +00:00
parent 2f7bc4fe8e
commit d7297248c1
11 changed files with 48 additions and 39 deletions

View File

@@ -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 { redirect } from 'next/navigation'
import { getInvitations } from '@/lib/sharing-actions' import { getInvitations } from '@/lib/sharing-actions'
import InvitationCard from '@/components/InvitationCard' import InvitationCard from '@/components/InvitationCard'
@@ -27,7 +28,7 @@ type Invitation = {
} }
export default async function InvitationsPage() { export default async function InvitationsPage() {
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user) { if (!session?.user) {
redirect('/auth/login') redirect('/auth/login')

View File

@@ -1,7 +1,8 @@
import { notFound } from 'next/navigation' import { notFound } from 'next/navigation'
import { getItem } from '@/lib/actions' import { getItem } from '@/lib/actions'
import { canEditList } from '@/lib/permissions' 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 ItemForm from '@/components/ItemForm'
import Link from 'next/link' import Link from 'next/link'
import { ArrowLeft } from 'lucide-react' import { ArrowLeft } from 'lucide-react'
@@ -16,7 +17,7 @@ interface PageProps {
} }
export default async function EditItemPage({ params }: PageProps) { export default async function EditItemPage({ params }: PageProps) {
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
notFound() notFound()
} }

View File

@@ -1,7 +1,8 @@
import { notFound } from 'next/navigation' import { notFound } from 'next/navigation'
import { getItem } from '@/lib/actions' import { getItem } from '@/lib/actions'
import { canEditList } from '@/lib/permissions' 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 ItemDetail from '@/components/ItemDetail'
import Link from 'next/link' import Link from 'next/link'
import { ArrowLeft, Edit } from 'lucide-react' import { ArrowLeft, Edit } from 'lucide-react'
@@ -18,7 +19,7 @@ interface PageProps {
} }
export default async function ItemDetailPage({ params }: PageProps) { export default async function ItemDetailPage({ params }: PageProps) {
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
notFound() notFound()
} }

View File

@@ -1,6 +1,7 @@
import { getListWithItems } from '@/lib/actions' import { getListWithItems } from '@/lib/actions'
import { getPermission } from '@/lib/permissions' 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 { notFound } from 'next/navigation'
import Link from 'next/link' import Link from 'next/link'
import { ArrowLeft } from 'lucide-react' import { ArrowLeft } from 'lucide-react'
@@ -10,7 +11,7 @@ import ListDetailView from '@/components/ListDetailView'
export const dynamic = 'force-dynamic' export const dynamic = 'force-dynamic'
export default async function ListDetailPage({ params }: { params: { id: string } }) { export default async function ListDetailPage({ params }: { params: { id: string } }) {
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
notFound() notFound()
} }

View File

@@ -4,13 +4,14 @@ import NewListButton from '@/components/NewListButton'
import GlobalSearch from '@/components/GlobalSearch' import GlobalSearch from '@/components/GlobalSearch'
import EmptyState from '@/components/EmptyState' import EmptyState from '@/components/EmptyState'
import Link from 'next/link' 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' import { redirect } from 'next/navigation'
export const dynamic = 'force-dynamic' export const dynamic = 'force-dynamic'
export default async function Home() { export default async function Home() {
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user) { if (!session?.user) {
redirect('/auth/login') redirect('/auth/login')

View File

@@ -1,5 +1,6 @@
import { redirect } from 'next/navigation' 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 { getUserProfile } from '@/lib/auth-actions'
import ProfileForm from '@/components/ProfileForm' import ProfileForm from '@/components/ProfileForm'
import PasswordChangeForm from '@/components/PasswordChangeForm' import PasswordChangeForm from '@/components/PasswordChangeForm'
@@ -11,7 +12,7 @@ export const metadata = {
} }
export default async function ProfilePage() { export default async function ProfilePage() {
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
redirect('/auth/login') redirect('/auth/login')

View File

@@ -15,7 +15,7 @@ vi.mock('@/auth', () => ({
// Import after mocking // Import after mocking
import { registerUser, loginUser } from '../auth-actions' import { registerUser, loginUser } from '../auth-actions'
import { signIn } from '@/auth' import { signIn } from 'next-auth/react'
describe('registerUser', () => { describe('registerUser', () => {
// Clean up test users after each test // Clean up test users after each test

View File

@@ -2,7 +2,8 @@
import { prisma } from './db' import { prisma } from './db'
import { revalidatePath } from 'next/cache' import { revalidatePath } from 'next/cache'
import { auth } from '@/auth' import { getServerSession } from 'next-auth'
import { authOptions } from '@/pages/api/auth/[...nextauth]'
import { import {
validateListTitle, validateListTitle,
validateItemTitle, validateItemTitle,
@@ -49,7 +50,7 @@ async function retryOperation<T>(
export async function getLists() { export async function getLists() {
try { try {
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to view lists') 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') { export async function createList(title: string, color: string = '#3B82F6') {
try { try {
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to create lists') throw new Error('Unauthorized: Please log in to create lists')
} }
@@ -157,7 +158,7 @@ export async function getListWithItems(listId: string) {
} }
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to view lists') throw new Error('Unauthorized: Please log in to view lists')
} }
@@ -228,7 +229,7 @@ export async function getItem(itemId: string) {
} }
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to view items') throw new Error('Unauthorized: Please log in to view items')
} }
@@ -305,7 +306,7 @@ export async function createItem(
} }
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to create items') throw new Error('Unauthorized: Please log in to create items')
} }
@@ -387,7 +388,7 @@ export async function toggleItem(itemId: string) {
} }
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to update items') throw new Error('Unauthorized: Please log in to update items')
} }
@@ -465,7 +466,7 @@ export async function updateItem(
} }
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to update items') throw new Error('Unauthorized: Please log in to update items')
} }
@@ -560,7 +561,7 @@ export async function deleteItem(itemId: string) {
} }
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to delete items') throw new Error('Unauthorized: Please log in to delete items')
} }
@@ -626,7 +627,7 @@ export async function deleteList(listId: string) {
} }
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to delete lists') throw new Error('Unauthorized: Please log in to delete lists')
} }
@@ -677,7 +678,7 @@ export async function updateList(
} }
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to update lists') 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 // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to search items') throw new Error('Unauthorized: Please log in to search items')
} }
@@ -878,7 +879,7 @@ export async function getItemsByFilter(
) { ) {
try { try {
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to filter items') throw new Error('Unauthorized: Please log in to filter items')
} }

View File

@@ -3,7 +3,7 @@
import { prisma } from './db' import { prisma } from './db'
import bcrypt from 'bcryptjs' import bcrypt from 'bcryptjs'
import { z } from 'zod' 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 { checkRateLimit, resetRateLimit, LOGIN_RATE_LIMIT, REGISTER_RATE_LIMIT } from './rate-limit'
import { headers } from 'next/headers' import { headers } from 'next/headers'
import { getClientIdentifier } from './rate-limit' import { getClientIdentifier } from './rate-limit'
@@ -196,7 +196,7 @@ export async function logoutUser(): Promise<void> {
export async function getCurrentSession() { export async function getCurrentSession() {
try { try {
const { auth } = await import('@/auth') const { auth } = await import('@/auth')
const session = await auth() const session = await getServerSession(authOptions)
return session return session
} catch (error) { } catch (error) {
console.error('Session retrieval error:', error) console.error('Session retrieval error:', error)

View File

@@ -1,7 +1,8 @@
'use server' 'use server'
import { prisma } from './db' 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 * Migration utilities for transitioning existing anonymous lists to user-owned lists
@@ -71,7 +72,7 @@ export async function getClaimableLists(listIds: string[]): Promise<ClaimableLis
export async function claimLists(listIds: string[]): Promise<MigrationResult> { export async function claimLists(listIds: string[]): Promise<MigrationResult> {
try { try {
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
return { success: false, error: 'Unauthorized: Please log in to claim lists' } return { success: false, error: 'Unauthorized: Please log in to claim lists' }
} }
@@ -116,7 +117,7 @@ export async function claimLists(listIds: string[]): Promise<MigrationResult> {
*/ */
export async function hasExistingLists(): Promise<boolean> { export async function hasExistingLists(): Promise<boolean> {
try { try {
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
return false return false
} }

View File

@@ -2,7 +2,8 @@
import { prisma } from './db' import { prisma } from './db'
import { revalidatePath } from 'next/cache' 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 { z } from 'zod'
import { checkRateLimit, INVITATION_RATE_LIMIT } from './rate-limit' import { checkRateLimit, INVITATION_RATE_LIMIT } from './rate-limit'
@@ -57,7 +58,7 @@ export async function inviteUserToList(
) { ) {
try { try {
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to invite users') throw new Error('Unauthorized: Please log in to invite users')
} }
@@ -187,7 +188,7 @@ export async function inviteUserToList(
export async function getInvitations() { export async function getInvitations() {
try { try {
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id || !session?.user?.email) { if (!session?.user?.id || !session?.user?.email) {
throw new Error('Unauthorized: Please log in to view invitations') throw new Error('Unauthorized: Please log in to view invitations')
} }
@@ -237,7 +238,7 @@ export async function getInvitations() {
export async function acceptInvitation(invitationId: string) { export async function acceptInvitation(invitationId: string) {
try { try {
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id || !session?.user?.email) { if (!session?.user?.id || !session?.user?.email) {
throw new Error('Unauthorized: Please log in to accept invitations') 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) { export async function declineInvitation(invitationId: string) {
try { try {
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id || !session?.user?.email) { if (!session?.user?.id || !session?.user?.email) {
throw new Error('Unauthorized: Please log in to decline invitations') 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) { export async function getCollaborators(listId: string) {
try { try {
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to view collaborators') throw new Error('Unauthorized: Please log in to view collaborators')
} }
@@ -488,7 +489,7 @@ export async function updateCollaboratorPermission(
) { ) {
try { try {
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to update permissions') throw new Error('Unauthorized: Please log in to update permissions')
} }
@@ -566,7 +567,7 @@ export async function removeCollaborator(
) { ) {
try { try {
// Get current user session // Get current user session
const session = await auth() const session = await getServerSession(authOptions)
if (!session?.user?.id) { if (!session?.user?.id) {
throw new Error('Unauthorized: Please log in to remove collaborators') throw new Error('Unauthorized: Please log in to remove collaborators')
} }