Skip to content

Commit 4e22b20

Browse files
authored
fix: add authentication to coupon and store creation endpoints (#18)
Fixes #17 POST /api/coupons and POST /api/stores had no authentication, allowing any unauthenticated request to create coupons and stores. Added getSessionDid() auth check matching the pattern used in other protected endpoints (POST /api/coupons/vote, POST /api/bounties).
1 parent d446c94 commit 4e22b20

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

apps/web/app/api/coupons/route.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NextRequest, NextResponse } from 'next/server';
22
import { getDb } from '@/lib/db';
3+
import { getSessionDid } from '@/lib/auth';
34

45
export async function GET(req: NextRequest) {
56
const { searchParams } = new URL(req.url);
@@ -23,6 +24,9 @@ export async function GET(req: NextRequest) {
2324
}
2425

2526
export async function POST(req: NextRequest) {
27+
const did = await getSessionDid();
28+
if (!did) return NextResponse.json({ error: 'Authentication required' }, { status: 401 });
29+
2630
try {
2731
const body = await req.json();
2832
const { store_id, code, title, description, discount, expiry_date, url } = body;

apps/web/app/api/stores/route.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { NextResponse } from 'next/server';
1+
import { NextRequest, NextResponse } from 'next/server';
22
import { getDb } from '@/lib/db';
3+
import { getSessionDid } from '@/lib/auth';
34

45
export async function GET() {
56
try {
@@ -18,7 +19,10 @@ export async function GET() {
1819
}
1920
}
2021

21-
export async function POST(req: Request) {
22+
export async function POST(req: NextRequest) {
23+
const did = await getSessionDid();
24+
if (!did) return NextResponse.json({ error: 'Authentication required' }, { status: 401 });
25+
2226
try {
2327
const body = await req.json();
2428
const { name, slug, logo_url, website, category_id } = body;

0 commit comments

Comments
 (0)