Files
my-links/inertia/hooks/use_auth.tsx
2025-12-10 05:12:14 +01:00

16 lines
456 B
TypeScript

import { UserAuth } from '#shared/types/dto';
import { PageProps } from '@adonisjs/inertia/types';
import { usePage } from '@inertiajs/react';
const useAuth = (): UserAuth => usePage<PageProps>().props.auth as UserAuth;
const withAuth = <T extends object>(
Component: React.ComponentType<T & { auth: UserAuth }>
) => {
return (props: T) => {
const auth = useAuth();
return <Component {...props} auth={auth} />;
};
};
export { useAuth, withAuth };