From 96fb9eee7c819f7cc3971e0be5ab47eb0d1dda71 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 21 Aug 2025 22:26:35 +0000 Subject: [PATCH] fix urls --- apps/deploy-fe/src/app/test-connection/page.tsx | 6 ++++-- apps/deploy-fe/src/components/AuthTest.tsx | 6 ++++-- apps/deploy-fe/src/components/DirectKeyAuth.tsx | 6 ++++-- apps/deploy-fe/src/components/GQLTest.tsx | 6 ++++-- apps/deploy-fe/src/components/providers.tsx | 2 +- apps/deploy-fe/src/context/BackendContext.tsx | 4 +++- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/deploy-fe/src/app/test-connection/page.tsx b/apps/deploy-fe/src/app/test-connection/page.tsx index 9c500d9..031311d 100644 --- a/apps/deploy-fe/src/app/test-connection/page.tsx +++ b/apps/deploy-fe/src/app/test-connection/page.tsx @@ -27,6 +27,8 @@ declare global { } } +const BACKEND_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000' + export default function TestConnectionPage() { // Get getToken from useAuth hook, not from user const { isSignedIn, isLoaded: isClerkLoaded, getToken } = useAuth() @@ -136,7 +138,7 @@ export default function TestConnectionPage() { const checkBackendConnection = async () => { try { // Test session - const response = await fetch('http://localhost:8000/auth/session', { + const response = await fetch(`${BACKEND_URL}/auth/session`, { method: 'GET', credentials: 'include', }) @@ -192,7 +194,7 @@ export default function TestConnectionPage() { const checkWalletConnection = async () => { if (isBackendConnected) { try { - const response = await fetch('http://localhost:8000/auth/session', { + const response = await fetch(`${BACKEND_URL}/auth/session`, { method: 'GET', credentials: 'include', }) diff --git a/apps/deploy-fe/src/components/AuthTest.tsx b/apps/deploy-fe/src/components/AuthTest.tsx index 91c92c6..e418f46 100644 --- a/apps/deploy-fe/src/components/AuthTest.tsx +++ b/apps/deploy-fe/src/components/AuthTest.tsx @@ -6,6 +6,8 @@ import { Button } from '@workspace/ui/components/button' import { CheckBalanceWrapper } from './iframe/check-balance-iframe/CheckBalanceWrapper' import { CopyIcon } from 'lucide-react' +const BACKEND_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000' + // Generate a random nonce function generateNonce() { return Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2); @@ -25,7 +27,7 @@ export function SIWEAuth() { const checkSession = async () => { try { setSessionStatus('checking') - const response = await fetch('http://localhost:8000/auth/session', { + const response = await fetch(`${BACKEND_URL}/auth/session`, { method: 'GET', credentials: 'include', }) @@ -171,7 +173,7 @@ Issued At: ${issuedAt}` setDebugInfo(prev => `${prev}\nRaw signature: ${signedMessage}`) // Try using the raw signature directly - const response = await fetch('http://localhost:8000/auth/validate', { + const response = await fetch(`${BACKEND_URL}/auth/validate`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/apps/deploy-fe/src/components/DirectKeyAuth.tsx b/apps/deploy-fe/src/components/DirectKeyAuth.tsx index 0dec34c..8f43202 100644 --- a/apps/deploy-fe/src/components/DirectKeyAuth.tsx +++ b/apps/deploy-fe/src/components/DirectKeyAuth.tsx @@ -4,6 +4,8 @@ import { useState, useEffect } from 'react' import { Button } from '@workspace/ui/components/button' import { Wallet } from 'ethers' // Add this to your package.json if not already there +const BACKEND_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000' + export function DirectKeyAuth() { const [sessionStatus, setSessionStatus] = useState<'checking' | 'authenticated' | 'unauthenticated'>('checking') const [sessionData, setSessionData] = useState(null) @@ -14,7 +16,7 @@ export function DirectKeyAuth() { const checkSession = async () => { try { setSessionStatus('checking') - const response = await fetch('http://localhost:8000/auth/session', { + const response = await fetch(`${BACKEND_URL}/auth/session`, { method: 'GET', credentials: 'include', }) @@ -79,7 +81,7 @@ Issued At: ${issuedAt}`; console.log('Generated signature:', signature); // Send to backend - const response = await fetch('http://localhost:8000/auth/validate', { + const response = await fetch(`${BACKEND_URL}/auth/validate`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/apps/deploy-fe/src/components/GQLTest.tsx b/apps/deploy-fe/src/components/GQLTest.tsx index 88d53ff..4426279 100644 --- a/apps/deploy-fe/src/components/GQLTest.tsx +++ b/apps/deploy-fe/src/components/GQLTest.tsx @@ -2,6 +2,8 @@ import { useEffect, useState } from 'react' import { useGQLClient } from '@/context' +const BACKEND_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000' + export function GQLTest() { const [testResponse, setTestResponse] = useState('Testing connection...') const [error, setError] = useState(null) @@ -11,7 +13,7 @@ export function GQLTest() { async function testGQLConnection() { try { // Try a direct GraphQL query using fetch - const response = await fetch('http://localhost:8000/graphql', { + const response = await fetch(`${BACKEND_URL}/graphql`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -50,7 +52,7 @@ export function GQLTest() { setTestResponse('Testing direct connection...') setError(null) - const response = await fetch('http://localhost:8000/auth/session', { + const response = await fetch(`${BACKEND_URL}/auth/session`, { method: 'GET', credentials: 'include', }) diff --git a/apps/deploy-fe/src/components/providers.tsx b/apps/deploy-fe/src/components/providers.tsx index bdfee3f..a78b902 100644 --- a/apps/deploy-fe/src/components/providers.tsx +++ b/apps/deploy-fe/src/components/providers.tsx @@ -19,7 +19,7 @@ export function Providers({ children }: { children: React.ReactNode }) { const initGQLClient = async () => { try { const client = new GQLClient({ - gqlEndpoint: 'http://localhost:8000/graphql', + gqlEndpoint: `${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'}/graphql`, }) setGqlClient(client) } catch (error) { diff --git a/apps/deploy-fe/src/context/BackendContext.tsx b/apps/deploy-fe/src/context/BackendContext.tsx index 3c92296..5aa6a1f 100644 --- a/apps/deploy-fe/src/context/BackendContext.tsx +++ b/apps/deploy-fe/src/context/BackendContext.tsx @@ -11,6 +11,8 @@ import { useCallback } from 'react' +const BACKEND_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000' + /** * @interface BackendContextType * @description Defines the structure of the BackendContext value. @@ -45,7 +47,7 @@ export const BackendProvider: React.FC<{ children: ReactNode }> = ({ // Check backend connection const checkBackendConnection = useCallback(async (): Promise => { try { - const response = await fetch('http://localhost:8000/auth/session', { + const response = await fetch(`${BACKEND_URL}/auth/session`, { method: 'GET', credentials: 'include', })