21 lines
562 B
TypeScript
21 lines
562 B
TypeScript
|
|
import { getAdminToken, useGetAdminSession } from 'infra/backend-api'
|
|||
|
|
|
|||
|
|
import type { AdminSession } from '../types/auth-api.type'
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Состояние текущей admin-сессии.
|
|||
|
|
*/
|
|||
|
|
export const useAdminSession = (): AdminSession => {
|
|||
|
|
const hasToken = Boolean(getAdminToken())
|
|||
|
|
const sessionQuery = useGetAdminSession({
|
|||
|
|
shouldRetryOnError: false,
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
error: sessionQuery.error,
|
|||
|
|
isAuthenticated: Boolean(sessionQuery.data),
|
|||
|
|
isLoading: hasToken && sessionQuery.isLoading,
|
|||
|
|
session: sessionQuery.data ?? null,
|
|||
|
|
}
|
|||
|
|
}
|