diff --git a/src/webapp/api-client/ApiClient.ts b/src/webapp/api-client/ApiClient.ts index 41357ae7..e6a0b659 100644 --- a/src/webapp/api-client/ApiClient.ts +++ b/src/webapp/api-client/ApiClient.ts @@ -265,14 +265,12 @@ export * from './types'; // Factory functions for different client types export const createApiClient = () => { return new ApiClient( - process.env.NEXT_PUBLIC_API_BASE_URL || 'http://127.0.0.1:3000' + process.env.NEXT_PUBLIC_API_BASE_URL || 'http://127.0.0.1:3000', ); }; export const createServerApiClient = () => { - return new ApiClient( - process.env.API_BASE_URL || 'http://127.0.0.1:3000' - ); + return new ApiClient(process.env.API_BASE_URL || 'http://127.0.0.1:3000'); }; // Default client instance for backward compatibility diff --git a/src/webapp/api-client/clients/BaseClient.ts b/src/webapp/api-client/clients/BaseClient.ts index 017f2203..b40b7176 100644 --- a/src/webapp/api-client/clients/BaseClient.ts +++ b/src/webapp/api-client/clients/BaseClient.ts @@ -20,10 +20,7 @@ export abstract class BaseClient { credentials: 'include', // Include cookies automatically (works for both client and server) }; - if ( - data && - (method === 'POST' || method === 'PUT' || method === 'PATCH') - ) { + if (data && (method === 'POST' || method === 'PUT' || method === 'PATCH')) { config.body = JSON.stringify(data); } diff --git a/src/webapp/app/api/auth/me/route.ts b/src/webapp/app/api/auth/me/route.ts index d6e16c7f..98543146 100644 --- a/src/webapp/app/api/auth/me/route.ts +++ b/src/webapp/app/api/auth/me/route.ts @@ -28,18 +28,14 @@ export async function GET(request: NextRequest) { // No tokens at all - not authenticated if (!accessToken && !refreshToken) { - return NextResponse.json( - { error: 'Not authenticated' }, - { status: 401 }, - ); + return NextResponse.json({ error: 'Not authenticated' }, { status: 401 }); } // Check if accessToken is expired or expiring soon (< 5 min) if (isTokenExpiringSoon(accessToken, 5) && refreshToken) { try { // Call backend to refresh tokens - const backendUrl = - process.env.API_BASE_URL || 'http://127.0.0.1:3000'; + const backendUrl = process.env.API_BASE_URL || 'http://127.0.0.1:3000'; const refreshResponse = await fetch( `${backendUrl}/api/users/oauth/refresh`, { diff --git a/src/webapp/hooks/useAuth.tsx b/src/webapp/hooks/useAuth.tsx index 697ffd0c..026fed35 100644 --- a/src/webapp/hooks/useAuth.tsx +++ b/src/webapp/hooks/useAuth.tsx @@ -1,6 +1,13 @@ 'use client'; -import { useState, useEffect, createContext, useContext, ReactNode, useCallback } from 'react'; +import { + useState, + useEffect, + createContext, + useContext, + ReactNode, + useCallback, +} from 'react'; import { useRouter } from 'next/navigation'; import { ClientCookieAuthService } from '@/services/auth'; import { ApiClient } from '@/api-client/ApiClient'; @@ -79,16 +86,19 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { useEffect(() => { if (!authState.isAuthenticated) return; - const interval = setInterval(async () => { - await refreshAuth(); - }, 5 * 60 * 1000); // Check every 5 minutes + const interval = setInterval( + async () => { + await refreshAuth(); + }, + 5 * 60 * 1000, + ); // Check every 5 minutes return () => clearInterval(interval); }, [authState.isAuthenticated, refreshAuth]); const login = useCallback(async (handle: string) => { const apiClient = new ApiClient( - process.env.NEXT_PUBLIC_API_BASE_URL || 'http://127.0.0.1:3000' + process.env.NEXT_PUBLIC_API_BASE_URL || 'http://127.0.0.1:3000', ); return await apiClient.initiateOAuthSignIn({ handle }); }, []); diff --git a/src/webapp/lib/serverAuth.ts b/src/webapp/lib/serverAuth.ts index d279aae5..14126989 100644 --- a/src/webapp/lib/serverAuth.ts +++ b/src/webapp/lib/serverAuth.ts @@ -25,7 +25,7 @@ export async function getServerAuthStatus(): Promise<{ method: 'GET', headers: { 'Content-Type': 'application/json', - 'Cookie': `accessToken=${accessToken}`, + Cookie: `accessToken=${accessToken}`, }, cache: 'no-store', }); diff --git a/src/webapp/services/auth/CookieAuthService.server.ts b/src/webapp/services/auth/CookieAuthService.server.ts index 715301ee..86d7dc21 100644 --- a/src/webapp/services/auth/CookieAuthService.server.ts +++ b/src/webapp/services/auth/CookieAuthService.server.ts @@ -16,7 +16,10 @@ export class ServerCookieAuthService { } // Check if token is expired (same logic as client) - static isTokenExpired(token: string | null, bufferMinutes: number = 5): boolean { + static isTokenExpired( + token: string | null, + bufferMinutes: number = 5, + ): boolean { if (!token) return true; try {