Added Arcjet Security and Updated Caching on Cards

This commit is contained in:
Ahmad 2024-12-27 18:00:27 -05:00
parent 06aac8524a
commit 611adcddff
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
9 changed files with 261 additions and 19 deletions

View file

@ -1,8 +1,31 @@
import arcjet, { fixedWindow } from '@/lib/arcjet';
import { unsplash } from '@/lib/unsplash';
import { auth } from '@clerk/nextjs/server';
import { NextResponse } from 'next/server';
export async function GET() {
const aj = arcjet.withRule(
fixedWindow({
mode: 'LIVE',
max: 10,
window: '60s',
})
);
export async function GET(req: Request) {
try {
const { orgId, userId } = await auth();
if (!orgId || !userId)
return new NextResponse(JSON.stringify({ error: 'Unauthorized' }), {
status: 401,
});
const decision = await aj.protect(req);
if (decision.isDenied())
return new NextResponse(
JSON.stringify({ error: 'Too many requests', reason: decision.reason }),
{ status: 429 }
);
const result = await unsplash.photos.getRandom({
collectionIds: ['317099'],
count: 9,