This commit is contained in:
Shreyaschorge 2025-07-15 21:38:47 +05:30
parent b366d97b53
commit 378ea65154
No known key found for this signature in database
8 changed files with 57 additions and 55 deletions

View File

@ -1,12 +1,12 @@
#!/usr/bin/env node #!/usr/bin/env node
import inquirer from 'inquirer';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import crypto from 'crypto'; import crypto from 'crypto';
import fs from 'fs';
import { dirname } from 'path';
import path from 'path';
import { fileURLToPath } from 'url';
import inquirer from 'inquirer';
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename); const __dirname = dirname(__filename);
@ -47,7 +47,7 @@ async function queryNeynarApp(apiKey) {
} }
try { try {
const response = await fetch( const response = await fetch(
`https://api.neynar.com/portal/app_by_api_key?starter_kit=true`, 'https://api.neynar.com/portal/app_by_api_key?starter_kit=true',
{ {
headers: { headers: {
'x-api-key': apiKey, 'x-api-key': apiKey,
@ -444,7 +444,7 @@ export async function init(
// Update package.json // Update package.json
console.log('\nUpdating package.json...'); console.log('\nUpdating package.json...');
const packageJsonPath = path.join(projectPath, 'package.json'); const packageJsonPath = path.join(projectPath, 'package.json');
let packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
packageJson.name = finalProjectName; packageJson.name = finalProjectName;
packageJson.version = '0.1.0'; packageJson.version = '0.1.0';

View File

@ -1,9 +1,9 @@
import localtunnel from 'localtunnel';
import { spawn } from 'child_process'; import { spawn } from 'child_process';
import { createServer } from 'net'; import { createServer } from 'net';
import dotenv from 'dotenv';
import path from 'path'; import path from 'path';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
import localtunnel from 'localtunnel';
// Load environment variables // Load environment variables
dotenv.config({ path: '.env.local' }); dotenv.config({ path: '.env.local' });
@ -96,7 +96,7 @@ async function startDev() {
? `1. Run: netstat -ano | findstr :${port}\n` + ? `1. Run: netstat -ano | findstr :${port}\n` +
'2. Note the PID (Process ID) from the output\n' + '2. Note the PID (Process ID) from the output\n' +
'3. Run: taskkill /PID <PID> /F\n' '3. Run: taskkill /PID <PID> /F\n'
: `On macOS/Linux, run:\nnpm run cleanup\n`) + : 'On macOS/Linux, run:\nnpm run cleanup\n') +
'\nThen try running this command again.', '\nThen try running this command again.',
); );
process.exit(1); process.exit(1);

View File

@ -8,10 +8,7 @@ export async function POST(request: Request) {
const { token } = await request.json(); const { token } = await request.json();
if (!token) { if (!token) {
return NextResponse.json( return NextResponse.json({ error: 'Token is required' }, { status: 400 });
{ error: 'Token is required' },
{ status: 400 }
);
} }
// Get domain from environment or request // Get domain from environment or request
@ -35,10 +32,7 @@ export async function POST(request: Request) {
} catch (e) { } catch (e) {
if (e instanceof Errors.InvalidTokenError) { if (e instanceof Errors.InvalidTokenError) {
console.info('Invalid token:', e.message); console.info('Invalid token:', e.message);
return NextResponse.json( return NextResponse.json({ error: 'Invalid token' }, { status: 401 });
{ error: 'Invalid token' },
{ status: 401 }
);
} }
throw e; throw e;
} }
@ -46,7 +40,7 @@ export async function POST(request: Request) {
console.error('Token validation error:', error); console.error('Token validation error:', error);
return NextResponse.json( return NextResponse.json(
{ error: 'Internal server error' }, { error: 'Internal server error' },
{ status: 500 } { status: 500 },
); );
} }
} }

View File

@ -1,5 +1,4 @@
import type { Metadata } from 'next'; import type { Metadata } from 'next';
import '~/app/globals.css'; import '~/app/globals.css';
import { Providers } from '~/app/providers'; import { Providers } from '~/app/providers';
import { APP_NAME, APP_DESCRIPTION } from '~/lib/constants'; import { APP_NAME, APP_DESCRIPTION } from '~/lib/constants';

View File

@ -16,8 +16,14 @@ export function ProfileButton({
useDetectClickOutside(ref, () => setShowDropdown(false)); useDetectClickOutside(ref, () => setShowDropdown(false));
const name = userData?.username && userData.username.trim() !== '' ? userData.username : `!${userData?.fid}`; const name =
const pfpUrl = userData?.pfpUrl && userData.pfpUrl.trim() !== '' ? userData.pfpUrl : 'https://farcaster.xyz/avatar.png'; userData?.username && userData.username.trim() !== ''
? userData.username
: `!${userData?.fid}`;
const pfpUrl =
userData?.pfpUrl && userData.pfpUrl.trim() !== ''
? userData.pfpUrl
: 'https://farcaster.xyz/avatar.png';
return ( return (
<div className="relative" ref={ref}> <div className="relative" ref={ref}>

View File

@ -1,13 +1,13 @@
'use client'; 'use client';
import { useCallback, useEffect, useState, useRef } from 'react'; import { useCallback, useEffect, useState, useRef } from 'react';
import { cn } from '~/lib/utils';
import { Button } from '~/components/ui/Button';
import { ProfileButton } from '~/components/ui/NeynarAuthButton/ProfileButton';
import { AuthDialog } from '~/components/ui/NeynarAuthButton/AuthDialog';
import { useMiniApp } from '@neynar/react';
import sdk, { SignIn as SignInCore } from '@farcaster/frame-sdk'; import sdk, { SignIn as SignInCore } from '@farcaster/frame-sdk';
import { useMiniApp } from '@neynar/react';
import { Button } from '~/components/ui/Button';
import { AuthDialog } from '~/components/ui/NeynarAuthButton/AuthDialog';
import { ProfileButton } from '~/components/ui/NeynarAuthButton/ProfileButton';
import { useQuickAuth } from '~/hooks/useQuickAuth'; import { useQuickAuth } from '~/hooks/useQuickAuth';
import { cn } from '~/lib/utils';
type User = { type User = {
fid: number; fid: number;
@ -142,7 +142,7 @@ export function NeynarAuthButton() {
const updateSessionWithSigners = useCallback( const updateSessionWithSigners = useCallback(
async ( async (
signers: StoredAuthState['signers'], signers: StoredAuthState['signers'],
user: StoredAuthState['user'], _user: StoredAuthState['user'],
) => { ) => {
if (!useBackendFlow) return; if (!useBackendFlow) return;
@ -392,7 +392,7 @@ export function NeynarAuthButton() {
setMessage(result.message); setMessage(result.message);
setSignature(result.signature); setSignature(result.signature);
// Use QuickAuth to sign in // Use QuickAuth to sign in
const signInResult = await quickAuthSignIn(); await quickAuthSignIn();
// Fetch user profile after sign in // Fetch user profile after sign in
if (quickAuthUser?.fid) { if (quickAuthUser?.fid) {
const user = await fetchUserData(quickAuthUser.fid); const user = await fetchUserData(quickAuthUser.fid);

View File

@ -1,9 +1,9 @@
'use client'; 'use client';
import { useCallback, useState } from 'react'; import { useCallback, useState } from 'react';
import sdk, { SignIn as SignInCore } from '@farcaster/miniapp-sdk'; import { SignIn as SignInCore } from '@farcaster/miniapp-sdk';
import { Button } from '../Button';
import { useQuickAuth } from '~/hooks/useQuickAuth'; import { useQuickAuth } from '~/hooks/useQuickAuth';
import { Button } from '../Button';
/** /**
* SignIn component handles Farcaster authentication using QuickAuth. * SignIn component handles Farcaster authentication using QuickAuth.

View File

@ -63,7 +63,8 @@ interface UseQuickAuthReturn {
*/ */
export function useQuickAuth(): UseQuickAuthReturn { export function useQuickAuth(): UseQuickAuthReturn {
// Current authenticated user data // Current authenticated user data
const [authenticatedUser, setAuthenticatedUser] = useState<AuthenticatedUser | null>(null); const [authenticatedUser, setAuthenticatedUser] =
useState<AuthenticatedUser | null>(null);
// Current authentication status // Current authentication status
const [status, setStatus] = useState<QuickAuthStatus>('loading'); const [status, setStatus] = useState<QuickAuthStatus>('loading');
@ -73,7 +74,9 @@ export function useQuickAuth(): UseQuickAuthReturn {
* @param {string} authToken - The JWT token to validate * @param {string} authToken - The JWT token to validate
* @returns {Promise<AuthenticatedUser | null>} User data if valid, null otherwise * @returns {Promise<AuthenticatedUser | null>} User data if valid, null otherwise
*/ */
const validateTokenWithServer = async (authToken: string): Promise<AuthenticatedUser | null> => { const validateTokenWithServer = async (
authToken: string,
): Promise<AuthenticatedUser | null> => {
try { try {
const validationResponse = await fetch('/api/auth/validate', { const validationResponse = await fetch('/api/auth/validate', {
method: 'POST', method: 'POST',