mirror of
https://github.com/yusufipk/RepoHub.git
synced 2026-09-12 02:56:07 +00:00
feat: Implement write authentication for API routes and add .env loading to init-db script.
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user