Update example env for account handle

This commit is contained in:
IshaVenikar 2025-02-05 19:14:43 +05:30
parent af864b4670
commit 20b4fe3182
3 changed files with 13 additions and 9 deletions

View File

@ -16,4 +16,4 @@ PINATA_GATEWAY=
# Change to your website URL # Change to your website URL
# For development: set to http://localhost:3000 # For development: set to http://localhost:3000
SITE_URL=https://memes.markto.market SITE_URL=https://memes.markto.market
ACCOUNT_HANDLE=mark_2_market1 NEXT_PUBLIC_ACCOUNT_HANDLE=

View File

@ -40,13 +40,16 @@ This project is a Solana-based meme generator that allows users to connect their
- Copy the JWT that is displayed - Copy the JWT that is displayed
- Add the following to `.env.example`: - Add the following to `.env`:
```env ```env
PINATA_JWT= PINATA_JWT=
# Get the gateway from https://app.pinata.cloud/gateway # Get the gateway from https://app.pinata.cloud/gateway
PINATA_GATEWAY= PINATA_GATEWAY=
# Add the account handle to be set in the tweet
NEXT_PUBLIC_ACCOUNT_HANDLE=
``` ```
- Run the development server: - Run the development server:

View File

@ -5,6 +5,7 @@ import { initializeDataSource } from '../../../data-source';
export async function POST(req: NextRequest): Promise<NextResponse> { export async function POST(req: NextRequest): Promise<NextResponse> {
try { try {
// TODO: Move initialization to server file
await initializeDataSource(); await initializeDataSource();
const { tweetUrl } = await req.json(); const { tweetUrl } = await req.json();
@ -13,23 +14,23 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
const response = await fetch(url); const response = await fetch(url);
const data = await response.json(); const data = await response.json();
const { handle, txHash } = extractData(data.html); const { handle, txSignature } = extractData(data.html);
if (!handle || !txHash) { if (!handle || !txSignature) {
return NextResponse.json( return NextResponse.json(
{ error: 'Verification failed' }, { error: 'Verification failed' },
{ status: 500 } { status: 500 }
) )
} }
const isSigVerified = await verifySignatureInTweet(txHash); const isSigVerified = await verifySignatureInTweet(txSignature);
const isHandleCorrect = handle === process.env.ACCOUNT_HANDLE; const isHandleCorrect = handle === process.env.NEXT_PUBLIC_ACCOUNT_HANDLE;
const isVerified = isSigVerified && isHandleCorrect; const isVerified = isSigVerified && isHandleCorrect;
if (!isVerified) { if (!isVerified) {
throw new Error('Tweet is not valid'); throw new Error('Tweet is not valid');
} }
const { isFourth } = await saveTweet({ transactionSignature: txHash }); const { isFourth } = await saveTweet({ transactionSignature: txSignature });
if (isFourth) { if (isFourth) {
createTokenLockForRecipient(); createTokenLockForRecipient();
} }
@ -50,12 +51,12 @@ const extractData = (tweet: string | object) => {
const decodedTweet = tweetText.replace(/&#39;/g, "'").replace(/&quot;/g, '"'); const decodedTweet = tweetText.replace(/&#39;/g, "'").replace(/&quot;/g, '"');
const urlMatch = decodedTweet.match(/<a href="(https:\/\/t.co\/[^"]+)">/); const urlMatch = decodedTweet.match(/<a href="(https:\/\/t.co\/[^"]+)">/);
const txHashMatch = decodedTweet.match(/TX Hash: '([^']+)'/); const txSignatureMatch = decodedTweet.match(/TX Hash: '([^']+)'/);
const handleMatch = decodedTweet.match(/@([A-Za-z0-9_]+)/); const handleMatch = decodedTweet.match(/@([A-Za-z0-9_]+)/);
return { return {
memeUrl: urlMatch ? urlMatch[1] : null, memeUrl: urlMatch ? urlMatch[1] : null,
txHash: txHashMatch ? txHashMatch[1].trim() : null, txSignature: txSignatureMatch ? txSignatureMatch[1].trim() : null,
handle: handleMatch ? handleMatch[1] : null, handle: handleMatch ? handleMatch[1] : null,
}; };
}; };