mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-12-07 18:02:33 -05:00
Revert "Merge pull request #15 from neynarxyz/shreyas-formatting"
This reverts commitb1fdfc19a9, reversing changes made tob9e2087bd8.
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
import { NextRequest } from 'next/server';
|
||||
import {
|
||||
ParseWebhookEvent,
|
||||
parseWebhookEvent,
|
||||
verifyAppKeyWithNeynar,
|
||||
} from '@farcaster/miniapp-node';
|
||||
import { APP_NAME } from '~/lib/constants';
|
||||
} from "@farcaster/miniapp-node";
|
||||
import { NextRequest } from "next/server";
|
||||
import { APP_NAME } from "~/lib/constants";
|
||||
import {
|
||||
deleteUserNotificationDetails,
|
||||
setUserNotificationDetails,
|
||||
} from '~/lib/kv';
|
||||
import { sendMiniAppNotification } from '~/lib/notifs';
|
||||
} from "~/lib/kv";
|
||||
import { sendMiniAppNotification } from "~/lib/notifs";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
// If Neynar is enabled, we don't need to handle webhooks here
|
||||
// as they will be handled by Neynar's webhook endpoint
|
||||
const neynarEnabled =
|
||||
process.env.NEYNAR_API_KEY && process.env.NEYNAR_CLIENT_ID;
|
||||
const neynarEnabled = process.env.NEYNAR_API_KEY && process.env.NEYNAR_CLIENT_ID;
|
||||
if (neynarEnabled) {
|
||||
return Response.json({ success: true });
|
||||
}
|
||||
@@ -29,24 +28,24 @@ export async function POST(request: NextRequest) {
|
||||
const error = e as ParseWebhookEvent.ErrorType;
|
||||
|
||||
switch (error.name) {
|
||||
case 'VerifyJsonFarcasterSignature.InvalidDataError':
|
||||
case 'VerifyJsonFarcasterSignature.InvalidEventDataError':
|
||||
case "VerifyJsonFarcasterSignature.InvalidDataError":
|
||||
case "VerifyJsonFarcasterSignature.InvalidEventDataError":
|
||||
// The request data is invalid
|
||||
return Response.json(
|
||||
{ success: false, error: error.message },
|
||||
{ status: 400 },
|
||||
{ status: 400 }
|
||||
);
|
||||
case 'VerifyJsonFarcasterSignature.InvalidAppKeyError':
|
||||
case "VerifyJsonFarcasterSignature.InvalidAppKeyError":
|
||||
// The app key is invalid
|
||||
return Response.json(
|
||||
{ success: false, error: error.message },
|
||||
{ status: 401 },
|
||||
{ status: 401 }
|
||||
);
|
||||
case 'VerifyJsonFarcasterSignature.VerifyAppKeyError':
|
||||
case "VerifyJsonFarcasterSignature.VerifyAppKeyError":
|
||||
// Internal error verifying the app key (caller may want to try again)
|
||||
return Response.json(
|
||||
{ success: false, error: error.message },
|
||||
{ status: 500 },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -57,33 +56,33 @@ export async function POST(request: NextRequest) {
|
||||
// Only handle notifications if Neynar is not enabled
|
||||
// When Neynar is enabled, notifications are handled through their webhook
|
||||
switch (event.event) {
|
||||
case 'frame_added':
|
||||
case "frame_added":
|
||||
if (event.notificationDetails) {
|
||||
await setUserNotificationDetails(fid, event.notificationDetails);
|
||||
await sendMiniAppNotification({
|
||||
fid,
|
||||
title: `Welcome to ${APP_NAME}`,
|
||||
body: 'Mini app is now added to your client',
|
||||
body: "Mini app is now added to your client",
|
||||
});
|
||||
} else {
|
||||
await deleteUserNotificationDetails(fid);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'frame_removed':
|
||||
case "frame_removed":
|
||||
await deleteUserNotificationDetails(fid);
|
||||
break;
|
||||
|
||||
case 'notifications_enabled':
|
||||
case "notifications_enabled":
|
||||
await setUserNotificationDetails(fid, event.notificationDetails);
|
||||
await sendMiniAppNotification({
|
||||
fid,
|
||||
title: `Welcome to ${APP_NAME}`,
|
||||
body: 'Notifications are now enabled',
|
||||
body: "Notifications are now enabled",
|
||||
});
|
||||
break;
|
||||
|
||||
case 'notifications_disabled':
|
||||
case "notifications_disabled":
|
||||
await deleteUserNotificationDetails(fid);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user