Skip to content

Commit

Permalink
logging redirect info
Browse files Browse the repository at this point in the history
  • Loading branch information
julien51 committed Jan 31, 2024
1 parent 93898a1 commit 39c0f97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/app/api/[message]/checkout/route.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import { getUserProfile, validateMessage } from "@/lib/farcaster";
import { getMessage } from "@/lib/messages";

export async function POST(
request: Request,
{ params }: { params: { message: string } }
) {
return Response.redirect(request.url, 302);
const body = await request.json();
const { trustedData } = body;

if (!trustedData) {
return new Response("Missing trustedData", { status: 441 });
}
const fcMessage = await validateMessage(trustedData.messageBytes);
if (!fcMessage.valid) {
return new Response("Invalid message", { status: 442 });
}

// Get the message URL so we can then redirect to it!
const posterProfile = await getUserProfile(
fcMessage.message.data.frameActionBody?.castId?.fid
);
console.log(posterProfile);
const checkoutRedirect = new URL(request.url);
checkoutRedirect.searchParams.append("cast", "redirect");

return Response.redirect(checkoutRedirect.toString(), 302);
}

export async function GET(
Expand Down
2 changes: 0 additions & 2 deletions src/app/api/[message]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ export async function POST(
const message = await getMessage(params.message);
const body = await request.json();
const { trustedData } = body;
console.log(JSON.stringify(body, null, 2));

if (!trustedData) {
return new Response("Missing trustedData", { status: 441 });
}
const fcMessage = await validateMessage(trustedData.messageBytes);
console.log(fcMessage.message.data);
if (!fcMessage.valid) {
return new Response("Invalid message", { status: 442 });
}
Expand Down

0 comments on commit 39c0f97

Please sign in to comment.