route guard the index

This commit is contained in:
Nate Kelley 2025-08-12 17:05:02 -06:00
parent bd37c7717b
commit 66623fb2a5
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
1 changed files with 5 additions and 2 deletions

View File

@ -1,11 +1,14 @@
import { createFileRoute } from '@tanstack/react-router';
import { createFileRoute, redirect } from '@tanstack/react-router';
import logo from '../logo.svg';
export const Route = createFileRoute('/')({
component: App,
beforeLoad: async ({ context }) => {
const hasUser = context.user;
console.log('hasUser', hasUser);
const isAnonymous = context.user?.is_anonymous;
if (!hasUser || isAnonymous) {
throw redirect({ to: '/auth/login' });
}
},
});