import { Link, Outlet, createFileRoute, redirect, useRouter, } from '@tanstack/solid-router' import { useAuth } from '../auth' export const Route = createFileRoute('/_auth')({ beforeLoad: ({ context, location }) => { // Check if user is authenticated if (!context.auth.isAuthenticated()) { console.log('User not authenticated, redirecting to login...') throw redirect({ to: '/login', search: { redirect: location.href, }, }) } console.log('User authenticated, proceeding...') }, component: AuthLayout, }) function AuthLayout() { const router = useRouter() const navigate = Route.useNavigate() const auth = useAuth() const handleLogout = () => { if (window.confirm('Are you sure you want to logout?')) { auth.logout().then(() => { router.invalidate().finally(() => { navigate({ to: '/login' }) }) }) } } return (

Authenticated Route

This route's content is only visible to authenticated users.


) }