Files
ember-market-frontend/hooks/useUser.ts
NotII bfc60012cf Add admin dashboard pages and restructure admin route
Introduces new admin dashboard pages for alerts, bans, invites, orders, settings, status, and vendors under app/dashboard/admin/. Moves the main admin page to the new dashboard structure and adds a shared admin layout. Updates sidebar configuration and adds supporting components and hooks for admin features.
2025-10-18 15:19:10 +01:00

51 lines
989 B
TypeScript

"use client"
import { useState, useEffect } from 'react'
import { clientFetch } from '@/lib/api-client'
interface Vendor {
_id: string;
username: string;
storeId: string;
pgpKey: string;
__v: number;
}
interface User {
vendor: Vendor;
}
export function useUser() {
const [user, setUser] = useState<User | null>(null)
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
const fetchUser = async () => {
try {
setLoading(true)
const userData = await clientFetch<User>("/auth/me")
setUser(userData)
setError(null)
} catch (err) {
console.error("Failed to fetch user:", err)
setError("Failed to fetch user data")
setUser(null)
} finally {
setLoading(false)
}
}
fetchUser()
}, [])
const isAdmin = user?.vendor?.username === 'admin1'
return {
user,
loading,
error,
isAdmin
}
}