mirror of
https://github.com/Hackdex-App/hackdex-website.git
synced 2026-04-25 07:27:47 -05:00
Add route for invalidating discover cache
This commit is contained in:
parent
899724c839
commit
82886ec2bb
19
src/app/api/discover/refresh/route.ts
Normal file
19
src/app/api/discover/refresh/route.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import { revalidateTag } from "next/cache";
|
||||||
|
import { checkUserRoles } from "@/utils/user";
|
||||||
|
import { createClient } from "@/utils/supabase/server";
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
const supa = await createClient();
|
||||||
|
const { data: user } = await supa.auth.getUser();
|
||||||
|
if (!user) {
|
||||||
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
const { isAdmin } = await checkUserRoles(supa);
|
||||||
|
if (!isAdmin) {
|
||||||
|
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidateTag("discover");
|
||||||
|
return NextResponse.redirect(new URL("/discover", req.url));
|
||||||
|
}
|
||||||
|
|
@ -328,7 +328,7 @@ export async function getDiscoverData(sort: DiscoverSortOption): Promise<Discove
|
||||||
} satisfies DiscoverDataResult;
|
} satisfies DiscoverDataResult;
|
||||||
},
|
},
|
||||||
[`discover-data:${sort}:${dayStamp}`], // Cache key
|
[`discover-data:${sort}:${dayStamp}`], // Cache key
|
||||||
{ revalidate: TIME_TO_LIVE } // Cache duration
|
{ revalidate: TIME_TO_LIVE, tags: ["discover"] } // Cache duration
|
||||||
);
|
);
|
||||||
|
|
||||||
return runner();
|
return runner();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user