feat: Implement write authentication for API routes and add .env loading to init-db script.

This commit is contained in:
Yusuf İpek
2025-11-24 03:01:45 +03:00
parent 02bb1a1e72
commit 0e4716db54
5 changed files with 89 additions and 2 deletions
+12 -2
View File
@@ -1,7 +1,17 @@
import { NextResponse } from 'next/server'
import { NextRequest, NextResponse } from 'next/server'
import { PlatformInitializer } from '@/services/platformInitializer'
import { SyncAuth } from '@/lib/sync/auth'
export async function POST(request: NextRequest) {
// Check auth
const auth = await SyncAuth.isWriteAllowed(request)
if (!auth.allowed) {
return NextResponse.json(
{ error: auth.reason || 'Unauthorized' },
{ status: 403 }
)
}
export async function POST() {
try {
await PlatformInitializer.initializePlatforms()
return NextResponse.json({
+10
View File
@@ -1,5 +1,6 @@
import { NextRequest, NextResponse } from 'next/server'
import { PackageService } from '@/services/packageService'
import { SyncAuth } from '@/lib/sync/auth'
export async function GET(
request: NextRequest,
@@ -54,6 +55,15 @@ export async function DELETE(
request: NextRequest,
{ params }: { params: { id: string } }
) {
// Check auth
const auth = await SyncAuth.isWriteAllowed(request)
if (!auth.allowed) {
return NextResponse.json(
{ error: auth.reason || 'Unauthorized' },
{ status: 403 }
)
}
try {
const success = await PackageService.delete(params.id)
+10
View File
@@ -1,5 +1,6 @@
import { NextRequest, NextResponse } from 'next/server'
import { PackageService } from '@/services/packageService'
import { SyncAuth } from '@/lib/sync/auth'
export async function GET(request: NextRequest) {
try {
@@ -40,6 +41,15 @@ export async function GET(request: NextRequest) {
}
export async function POST(request: NextRequest) {
// Check auth
const auth = await SyncAuth.isWriteAllowed(request)
if (!auth.allowed) {
return NextResponse.json(
{ error: auth.reason || 'Unauthorized' },
{ status: 403 }
)
}
try {
const body = await request.json()
const packageData = await PackageService.create(body)