Connect annotator to real API: JWT login, services real-mode, Konva canvas, autosave, paginated images, tracing
This commit is contained in:
parent
59fc3efca6
commit
e010bb5558
38 changed files with 1880 additions and 529 deletions
|
|
@ -4,6 +4,15 @@ import { useAuthStore } from '@/stores/authStore'
|
|||
import { LoginRequest, UserRole } from '@/types'
|
||||
import { canApproveLabels, canCreateProject, canManageUsers } from '@/utils/permissions'
|
||||
|
||||
// Prefer the server's message (e.g. FastAPI `detail`) over axios' generic text.
|
||||
function readServerMessage(err: unknown): string | null {
|
||||
if (typeof err === 'object' && err !== null && 'response' in err) {
|
||||
const detail = (err as { response?: { data?: { detail?: unknown } } }).response?.data?.detail
|
||||
if (typeof detail === 'string' && detail.trim() !== '') return detail
|
||||
}
|
||||
return err instanceof Error ? err.message : null
|
||||
}
|
||||
|
||||
export function useAuth() {
|
||||
const { user, isAuthenticated, login: storeLogin, logout: storeLogout, setUser, setRole } = useAuthStore()
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
|
@ -17,9 +26,9 @@ export function useAuth() {
|
|||
storeLogin(response.user, response.accessToken)
|
||||
return response
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Đăng nhập thất bại'
|
||||
const message = readServerMessage(err) ?? 'Đăng nhập thất bại'
|
||||
setError(message)
|
||||
throw err
|
||||
throw new Error(message)
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue