change user membership without payment
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
import { NextRequest } from 'next/server'
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/plans/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
69
frontend/app/api/account/membership/route.ts
Normal file
69
frontend/app/api/account/membership/route.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { NextRequest } from 'next/server'
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/plans/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export async function PATCH(req: NextRequest) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
if (!session) {
|
||||
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
|
||||
status: 401,
|
||||
})
|
||||
}
|
||||
|
||||
const data = await req.json()
|
||||
|
||||
const requestBody = {
|
||||
account_type: data.plan,
|
||||
}
|
||||
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/account/change_membership/`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${session.accessToken}`,
|
||||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json()
|
||||
console.error('API Route - Backend 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('API Route - Error:', error)
|
||||
return new Response(JSON.stringify({ error: 'Internal Server Error' }), {
|
||||
status: 500,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user