mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-12-05 17:02:33 -05:00
Add notification savings + webhook validation
This commit is contained in:
committed by
lucas-neynar
parent
af451b12a1
commit
8acf07b03e
32
src/lib/kv.ts
Normal file
32
src/lib/kv.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { FrameNotificationDetails } from "@farcaster/frame-sdk";
|
||||
import { Redis } from "@upstash/redis";
|
||||
|
||||
const redis = new Redis({
|
||||
url: process.env.KV_REST_API_URL,
|
||||
token: process.env.KV_REST_API_TOKEN,
|
||||
});
|
||||
|
||||
function getUserNotificationDetailsKey(fid: number): string {
|
||||
return `frames-v2-demo:user:${fid}`;
|
||||
}
|
||||
|
||||
export async function getUserNotificationDetails(
|
||||
fid: number
|
||||
): Promise<FrameNotificationDetails | null> {
|
||||
return await redis.get<FrameNotificationDetails>(
|
||||
getUserNotificationDetailsKey(fid)
|
||||
);
|
||||
}
|
||||
|
||||
export async function setUserNotificationDetails(
|
||||
fid: number,
|
||||
notificationDetails: FrameNotificationDetails
|
||||
): Promise<void> {
|
||||
await redis.set(getUserNotificationDetailsKey(fid), notificationDetails);
|
||||
}
|
||||
|
||||
export async function deleteUserNotificationDetails(
|
||||
fid: number
|
||||
): Promise<void> {
|
||||
await redis.del(getUserNotificationDetailsKey(fid));
|
||||
}
|
||||
Reference in New Issue
Block a user