From b2adfa0357615d8b410fe7cc7682a60ac1d1864f Mon Sep 17 00:00:00 2001 From: JohnDoe6345789 Date: Thu, 25 Dec 2025 14:56:13 +0000 Subject: [PATCH] fix: add useAuth hook and fix useGitHubFetcher API call - Create useAuth hook for authentication state management - Export useAuth and useIsMobile correctly from hooks/index.ts - Fix listWorkflowRuns to listWorkflowRunsForRepo (correct Octokit API) - Add level property to AuthUser interface for permission system --- frontends/nextjs/src/hooks/index.ts | 4 +- frontends/nextjs/src/hooks/useAuth.ts | 93 +++++++++++++++++++ .../nextjs/src/hooks/useGitHubFetcher.ts | 2 +- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 frontends/nextjs/src/hooks/useAuth.ts diff --git a/frontends/nextjs/src/hooks/index.ts b/frontends/nextjs/src/hooks/index.ts index 12959112d..99c920496 100644 --- a/frontends/nextjs/src/hooks/index.ts +++ b/frontends/nextjs/src/hooks/index.ts @@ -1,11 +1,13 @@ +export { useAuth } from './useAuth' export { useAutoRefresh } from './useAutoRefresh' export { useCodeEditor } from './useCodeEditor' export { useDBAL } from './useDBAL' export { useFileTree } from './useFileTree' export { useGitHubFetcher } from './useGitHubFetcher' export { useKV } from './useKV' -export { useMobile } from './use-mobile' +export { useIsMobile } from './use-mobile' +export type { AuthUser, AuthState, UseAuthReturn } from './useAuth' export type { EditorFile } from './useCodeEditor' export type { FileNode } from './useFileTree' export type { WorkflowRun } from './useGitHubFetcher' diff --git a/frontends/nextjs/src/hooks/useAuth.ts b/frontends/nextjs/src/hooks/useAuth.ts new file mode 100644 index 000000000..0487e5a58 --- /dev/null +++ b/frontends/nextjs/src/hooks/useAuth.ts @@ -0,0 +1,93 @@ +/** + * useAuth hook - simple authentication state management + * Provides user authentication state and methods + */ +import { useState, useEffect, useCallback } from 'react' + +export interface AuthUser { + id: string + email: string + name?: string + role?: 'user' | 'admin' | 'god' | 'supergod' + level?: number +} + +export interface AuthState { + user: AuthUser | null + isAuthenticated: boolean + isLoading: boolean +} + +export interface UseAuthReturn extends AuthState { + login: (email: string, password: string) => Promise + logout: () => Promise + refresh: () => Promise +} + +// Simple in-memory auth state for now +// TODO: Implement proper auth with backend/Prisma +let authState: AuthState = { + user: null, + isAuthenticated: false, + isLoading: false, +} + +const listeners = new Set<() => void>() + +function notifyListeners() { + listeners.forEach((listener) => listener()) +} + +export function useAuth(): UseAuthReturn { + const [state, setState] = useState(authState) + + useEffect(() => { + const listener = () => setState({ ...authState }) + listeners.add(listener) + return () => { + listeners.delete(listener) + } + }, []) + + const login = useCallback(async (email: string, _password: string) => { + authState = { ...authState, isLoading: true } + notifyListeners() + + // Simulate API call + await new Promise((resolve) => setTimeout(resolve, 100)) + + authState = { + user: { id: '1', email, name: email.split('@')[0] }, + isAuthenticated: true, + isLoading: false, + } + notifyListeners() + }, []) + + const logout = useCallback(async () => { + authState = { ...authState, isLoading: true } + notifyListeners() + + await new Promise((resolve) => setTimeout(resolve, 100)) + + authState = { + user: null, + isAuthenticated: false, + isLoading: false, + } + notifyListeners() + }, []) + + const refresh = useCallback(async () => { + // No-op for now, would refresh token/session + }, []) + + return { + ...state, + login, + logout, + refresh, + } +} + +export default useAuth diff --git a/frontends/nextjs/src/hooks/useGitHubFetcher.ts b/frontends/nextjs/src/hooks/useGitHubFetcher.ts index edf1cc31c..8e717d339 100644 --- a/frontends/nextjs/src/hooks/useGitHubFetcher.ts +++ b/frontends/nextjs/src/hooks/useGitHubFetcher.ts @@ -48,7 +48,7 @@ export function useGitHubFetcher(): UseGitHubFetcherState & UseGitHubFetcherActi } const octokit = new Octokit({ auth: token }) - const response = await octokit.rest.actions.listWorkflowRuns({ + const response = await octokit.rest.actions.listWorkflowRunsForRepo({ owner: 'johndoe6345789', repo: 'metabuilder', per_page: 10,