Fix all NextAuth v4 imports across codebase
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<T>(
|
||||
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')
|
||||
}
|
||||
|
||||
@@ -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<void> {
|
||||
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)
|
||||
|
||||
@@ -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<ClaimableLis
|
||||
export async function claimLists(listIds: string[]): Promise<MigrationResult> {
|
||||
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<MigrationResult> {
|
||||
*/
|
||||
export async function hasExistingLists(): Promise<boolean> {
|
||||
try {
|
||||
const session = await auth()
|
||||
const session = await getServerSession(authOptions)
|
||||
if (!session?.user?.id) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user