mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
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
This commit is contained in:
@@ -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'
|
||||
|
||||
93
frontends/nextjs/src/hooks/useAuth.ts
Normal file
93
frontends/nextjs/src/hooks/useAuth.ts
Normal file
@@ -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<void>
|
||||
logout: () => Promise<void>
|
||||
refresh: () => Promise<void>
|
||||
}
|
||||
|
||||
// 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>(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
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user