Skip to content

Commit

Permalink
Refactored revalidate
Browse files Browse the repository at this point in the history
  • Loading branch information
mohdjami committed Jan 3, 2025
1 parent 824d1cc commit 0cec3d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/api/credits/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createClient } from "@/utils/supabase/server";
import { getServerUser } from "@/utils/users/server";
import { revalidatePath } from "next/cache";
import { NextResponse } from "next/server";

export async function GET(req: Request, res: Response) {
Expand All @@ -19,6 +20,7 @@ export async function GET(req: Request, res: Response) {
console.log(error);
return NextResponse.json({ error }, { status: 400 });
}
revalidatePath("/");
return NextResponse.json({ credits: data?.credits });
} catch (error) {
console.log(error);
Expand Down
2 changes: 2 additions & 0 deletions app/api/process/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createUserPreferences,
updateUserCredits,
} from "@/utils/db/db";
import { revalidatePath } from "next/cache";

export const POST = verifySignatureAppRouter(async (req: Request) => {
const body = await req.json();
Expand All @@ -20,6 +21,7 @@ export const POST = verifySignatureAppRouter(async (req: Request) => {
);
await createResponse(body.name, body.json, body.userid);
await updateUserCredits(body.userid);
revalidatePath("/");
} catch (error) {
console.log(error);
return new Response(`Error: ${error}`);
Expand Down
6 changes: 4 additions & 2 deletions app/api/user/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createClient } from "@/utils/supabase/server";
import { revalidatePath } from "next/cache";
import { NextRequest, NextResponse } from "next/server";

export async function PUT(request: NextRequest) {
export async function PUT(req: NextRequest) {
try {
const { name, email, bio, avatar_url, id } = await request.json();
const { name, id } = await req.json();
const supabase = createClient();
const { data, error } = await supabase
.from("users")
Expand All @@ -15,6 +16,7 @@ export async function PUT(request: NextRequest) {
if (error) {
return NextResponse.json({ error }, { status: 400 });
}
revalidatePath("/");
return NextResponse.json({ data });
} catch (error) {
console.log(error);
Expand Down

0 comments on commit 0cec3d2

Please sign in to comment.