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
# For development: set to http://localhost:3000
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
- Add the following to `.env.example`:
- Add the following to `.env`:
```env
PINATA_JWT=
# Get the gateway from https://app.pinata.cloud/gateway
PINATA_GATEWAY=
# Add the account handle to be set in the tweet
NEXT_PUBLIC_ACCOUNT_HANDLE=
```
- Run the development server:

View File

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