mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-11 16:53:05 +00:00
16 lines
456 B
TypeScript
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 };
|