- Introduced `useAuthentication` hook to handle session state, PIN verification, and offline mode logic. - Updated `useRouter` to include type definitions for better navigation instance typing. - Refined authentication flow with error handling, user session initialization, and token validation.
27 lines
697 B
TypeScript
27 lines
697 B
TypeScript
import {useNavigate, useParams as useRouterParams, Link, useLocation} from 'react-router-dom';
|
|
|
|
export type AppRouterInstance = {
|
|
push: (path: string) => void;
|
|
replace: (path: string) => void;
|
|
back: () => void;
|
|
};
|
|
|
|
function useRouter(): AppRouterInstance {
|
|
const navigate = useNavigate();
|
|
return {
|
|
push: (path: string) => navigate(path),
|
|
replace: (path: string) => navigate(path, {replace: true}),
|
|
back: () => navigate(-1),
|
|
};
|
|
}
|
|
|
|
function useParams<T extends Record<string, string>>(): T {
|
|
return useRouterParams() as T;
|
|
}
|
|
|
|
function usePathname(): string {
|
|
return useLocation().pathname;
|
|
}
|
|
|
|
export {Link, useRouter, useParams, usePathname};
|