Files
tripwithbonus/frontend/app/api/account/requests/route.ts
2025-05-27 15:07:33 +03:00

38 lines
1.1 KiB
TypeScript

import { getServerSession } from 'next-auth'
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
export async function GET() {
try {
const session = await getServerSession(authOptions)
if (!session) {
console.error('No session found')
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
status: 401,
})
}
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/account/leads/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${session.accessToken}`,
},
})
if (!response.ok) {
const error = await response.json()
console.error('API error:', error)
return new Response(JSON.stringify(error), { status: response.status })
}
const result = await response.json()
return new Response(JSON.stringify(result), { status: 200 })
} catch (error) {
console.error('Route handler error:', error)
return new Response(JSON.stringify({ error: 'Internal Server Error' }), {
status: 500,
})
}
}