feat: implement API composables for authentication and data fetching
- Add useApiFetch composable for HTTP requests with auth token - Implement useAuth composable for authentication endpoints - Add useAdmin composable for admin operations - Add useOperator composable for operator management - Add useMembers composable for member data - Add usePublic composable for public reports - Add useReports composable for report operations Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { defu } from 'defu'
|
||||
|
||||
export const useApiFetch = <T>(request: string, options: Parameters<typeof $fetch>[1] = {}) => {
|
||||
const config = useRuntimeConfig()
|
||||
const token = useCookie('auth_token') // Make sure this matches the cookie name you use on login
|
||||
|
||||
const defaults: Parameters<typeof $fetch>[1] = {
|
||||
baseURL: config.public.api as string,
|
||||
headers: token.value ? { Authorization: `Bearer ${token.value}` } : {},
|
||||
}
|
||||
|
||||
const params = defu(options, defaults)
|
||||
|
||||
return $fetch<T>(request, params)
|
||||
}
|
||||
Reference in New Issue
Block a user