feat: update default layout

This commit is contained in:
Sonny
2025-08-06 19:50:53 +02:00
parent d56bd1ef80
commit 97ba56b1e7
36 changed files with 627 additions and 119 deletions

View File

@@ -0,0 +1,25 @@
import { usePage } from '@inertiajs/react';
import type { Auth, InertiaPage } from '~/types/inertia';
export const useAuth = () => usePage<InertiaPage>().props.auth;
export const withAuth = <T extends object>(
Component: React.ComponentType<T & { auth: Auth }>
): React.ComponentType<Omit<T, 'auth'>> => {
return (props: Omit<T, 'auth'>) => {
const auth = useAuth();
return <Component {...(props as T)} auth={auth} />;
};
};
export const withAuthRequired = <T extends object>(
Component: React.ComponentType<T & { auth: Auth }>
): React.ComponentType<Omit<T, 'auth'>> => {
return (props: Omit<T, 'auth'>) => {
const auth = useAuth();
if (!auth.isAuthenticated) {
return null;
}
return <Component {...(props as T)} auth={auth} />;
};
};

View File

@@ -1,5 +0,0 @@
import { usePage } from '@inertiajs/react';
import type { InertiaPage } from '~/types/inertia';
const useUser = () => usePage<InertiaPage>().props.auth;
export default useUser;